image - How to get bits of an 8-bit binary column array into separate columns or separate arrays? -


consider following array:

>> a=[26;94;32]; >> b=dec2bin(a,8); >> c=str2num(b); >> d1=bitget(c,1); >> d2=bitget(c,2); >> d3=bitget(c,3); >> d4=bitget(c,4); >> d5=bitget(c,5); >> d6=bitget(c,6); >> d7=bitget(c,7); >> d8=bitget(c,8); >> e1=bitget(a,1); >> e2=bitget(a,2); >> e3=bitget(a,3); >> e4=bitget(a,4); >> e5=bitget(a,5); >> e6=bitget(a,6); >> e7=bitget(a,7); >> e8=bitget(a,8);   

i expect these results code:

d1 = e1   d2 = e2 d3 = e3   d4 = e4 d5 = e5 d6 = e6 d7 = e7 d8 = e8   

but have results:

d1 = e1   d2 = e2 d3 = e3   d4 != e4 d5 != e5 d6 != e6 d7 != e7 d8 != e8   

could please tell me why?

in fact want separately write bits of b or c in different columns of array or in different column arrays , use in bitplane slicing.
don't want use bitget directly ( it's homework assignment of image processing class , professor has emphasized on not using matlab image processing functions directly). please tell me how can without slowing down code?

there possibilities want.

the first mentioned divakar:

b = dec2bin(a,8) c = b-'0' 

will return:

c =       0     0     0     1     1     0     1     0      0     1     0     1     1     1     1     0      0     0     1     0     0     0     0     0 

but not how matlab internally works bit arrays, instead assumes "mirrored" orientation of bits.

to achieve use de2bi:

c = de2bi(a,8) 

which give you:

c =       0     1     0     1     1     0     0     0      0     1     1     1     1     0     1     0      0     0     0     0     0     1     0     0 

these arrays suitable function bitget, works "mirrored" orientation. why got wrong results.

so second solution comparison works fine:

d6 = c(:,6) e6 = bitget(a,6)  d6 =       0      1      0   e6 =       0      1      0 

unfortunately de2bi requires communications system toolbox, if don't have need adjust divakars solution to:

b = dec2bin(a,8) c = fliplr(b-'0') 

final comparison:

e = [ bitget(a,1),bitget(a,2),bitget(a,3),bitget(a,4), ...           bitget(a,5),bitget(a,6),bitget(a,7),bitget(a,8) ] comp = all( c == e ,3 )  comp =       1     1     1     1     1     1     1     1      1     1     1     1     1     1     1     1      1     1     1     1     1     1     1     1 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -