Why is de2bi not working for large decimal number?

I am using de2bi in an attempt to convert from 1582000000 to a 32 digit binary number.
data=de2bi(data,32,2,'left-msb'); where data is 1582000000.
The left-most 16 digits are correct, but the right-most 16 digits are not. What am I doing wrong??
Thanks!

 Accepted Answer

You are doing anything wrong.
But, using option 'left-msb' you are telling Matlab to consider right digits as higher order. So you get an "inverted" binary number. Maybe you want to use the classical binary representation with right-most higher order digits.
data=1582000000;
d=de2bi(data,32,2);
%check
n=bi2de(d)

2 Comments

Thanks. I didn't realize I was doing an inversion, I thought the 'left-msb' option was literally just supposed to swap the bits. Is there a way to swap the bits then so the MSB is the left more digit? Thanks!
Yes basically the 'left'msb' swaps the bits from right to left (it flips the whole bytes), infact you have:
de2bi(data,32,2,'left-msb')==flip(de2bi(data,32,2))
If this answer heped you, please accept :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!