How could I convert array of digits to a binary number? For instance:
a=[1 0 1 0 1 0]
I would like to convert to a binary number
b=101010
Is it possible to do without loops?
Maybe this is what you want:
char(a+'0')
Example:
>> a=[1 0 1 0 1 0]
a =
1 0 1 0 1 0
>> char(a+'0')
ans =
101010
This works by converting each number to its ASCII code (+'0'
) and then converting the vector of resulting numbers to a string (char()
).
You can convert it to a string:
sprintf('%d',a)
which I think is the only alternative to an array of logicals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With