Reputation: 19
In Matlab, I need to convert a decimal number into the binary and the converted binary number into the double number.
for example:
a= 3151;
b=dec2bin(a);
b=str2double(b);
I need the answer b=110001001111 but instead of it, 1.1000e+11 will appear.
I need the lsb of the binary number and the functions below will accept only double numbers not binaries as strings.
How can I fix this issue? Thanks for your support.
Upvotes: 1
Views: 89
Reputation: 1190
Usually you need to change matlab formatting with format short
, format long
etc. if you want to alter the way that numbers are displayed. I think you can use format long g
which will work the way you want, though I never used it before.
format long g;
b
b =
110001001111
Another way to deal with this is to tell matlab to specifically print the variable a certain way, like this:
format short;
sprintf('%i', b)
ans =
110001001111
Upvotes: 1