0

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
  • Sure. Store the binary values in an integer type of the proper size. Then they will be scalars. Commented May 8, 2018 at 19:39

1 Answer 1

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.