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?
Asked
Active
Viewed 108 times
0

Cris Luengo
- 55,762
- 10
- 62
- 120

videbar
- 21
- 2
-
Sure. Store the binary values in an integer type of the proper size. Then they will be scalars. – beaker May 08 '18 at 19:39
1 Answers
1
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.)

Cris Luengo
- 55,762
- 10
- 62
- 120