What is the best way to convert a vector of integers to binary in simulink?

Unfortunately, I do not have the Communications system Toolbox, and I am trying to convert a vector of integers into their binary numbers. I have tried using a 1-D lookup table and a Data Type Conversion box, but I am still not getting the results I am looking for.

Answers (2)

You can use Matlab function block with this code
function b=decimal2binary(n,nB)
%n your number
%nB number of bits, =16 in your case
n=1852
nB=16
b=2.^[nB-1:-1:0];
bit=zeros(1,nB);
for k=1:numel(b)
if n>=b(k)
bit(k)=1;
n=n-b(k);
end
end
When you can call a Matlab function:
function Bin = toBinary(value, nBit)
Bin = rem(floor(value(:) * pow2((1 - nBit):0)), 2)

Asked:

on 5 Jun 2013

Community Treasure Hunt

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

Start Hunting!