uint32 and uint64 binary display

21 views (last 30 days)
William
William on 14 Mar 2012
When using the uint32 and uint64 command as in
Answer = uint32(137)
I still get 137 back and not a binary number 32 bits long. Is there a way to output a 32 bit or a 64 bit binary number which I can then perform operations on and get a binary number returned?
Thanks

Answers (2)

Walter Roberson
Walter Roberson on 14 Mar 2012
No.
There are a few commands such as bin2dec() and dec2bin(), but there are no other MATLAB routines defined on strings or numeric vectors that happen to represent binary.
The binary operations such as bitxor() work on unsigned integers or arrays of unsigned integers.
uint32(137) does not mean that the value 137 is to be represented as a 32 bit binary string: uint32(137) means that the value is to be treated as an unsigned integral datatype consisting of 32 total bits. "integral datatype" just like Fortran's INTEGER or C's int .

Jan
Jan on 15 Mar 2012
uint32(137) does reply a binary 32 bit value. It is only displayed as a decimal when printed to a file or the command line. You can perform operations on this value as expected:
disp(uint32(137) - uint32(1000))

Community Treasure Hunt

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

Start Hunting!