How to remove MSB bit from a binary number?

5 ビュー (過去 30 日間)
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 8 日
コメント済み: aditya kumar sahu 2016 年 11 月 10 日
suppose i have an cell array 'c' of 1*256 size.
let c(1)=10010000
i want
p1= 10010000;
p2=0010000;
p3=010000;
p4=10000;
p5=0000;
p6=000;
p7=00;
p8=0;
it means in each step the MSB should be removed.. Thank you..plz any body suggest...
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 11 月 8 日
What is the the data type?
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 8 日
it is actually uint8 .but i have converted it into char..so we can do in both ways

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 8 日
cellfun(@(b) arrayfun(@(idx) b(idx:end), 1:length(b), 'uniform', 0), c, 'uniform', 0)
  4 件のコメント
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 9 日
編集済み: Guillaume 2016 年 11 月 9 日
>> a=imread('f.jpg');
>> b=imresize(a,[16 16]);
>> d = cellstr(dec2bin(b,8))';
>> for i = 1 : rows
for j = 1 : columns
suppose d{i,j}==11000001
i want d{i,j} should be decreased to 7 bit next 6 bit next 5 bit upto 2 bit.i.e. d(i,j)=1000001; d(i,j)=000001; d(i,j)=00001; d(i,j)=0001; d(i,j)=001;d(i,j)=01;..i.e at each step msb bits should be removed.
Walter Roberson
Walter Roberson 2016 年 11 月 9 日
That is what my first code does provided you start with cell array of string

サインインしてコメントする。

その他の回答 (1 件)

Guillaume
Guillaume 2016 年 11 月 9 日
b = imresize(imread('f.jpg'), [16 1]);
d = arrayun(@(s) bitshift(b, -s), 1:8, 'UniformOutput', false);
d{1} is all the values of b shifted by 1 bit, d{2} is all the values of b shifted by 2 bits, ... d{8} is all the values of b shifted by 8 bits.
There is absolutely no point in converting numbers in strings of 0 and 1 to manipulate bits Computers are much better at manipulating bits of numbers than they are at manipulating characters of strings.
You can always convert the d{i} to strings if you really wish to.
  1 件のコメント
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 10 日
Thank you to Walter Roberson & Guillaume...i got it...

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by