Work with binary numbers as scalars in Matlab

128 Views Asked by At

I am working with a MATLAB function that uses numbers in the binary base. To do so it uses the function dec2bin to transform an integer into a char array containing the binary information. The issue is that I plan to use HDL Coder to generate a HDL version of the function. One step of the process is to convert the variables to fixed point. This can be done automatically when the data is a scalar, so is there any way to manage binary numbers without using vectors?

1

There are 1 best solutions below

0
Cris Luengo On

dec2bin is just for display purposes. Numbers are always stored in the computer using binary representation. You can use the functions bitand, bitor, bitxor, bitcmp, bitshift, bitget, and bitset to do bit-wise manipulation of integer numbers:

>> a = uint32(7);
>> b = uint32(12);
>> bitand(a, b)
ans =
  uint32
   4

(Click on the function names above for the documentation. You can also do help bitand in MATLAB to read a shorter version of the documentation or doc bitand to read the full documentation.)