how to convert a single row matrix into an n bit number

4 views (last 30 days)
I am given a numerical array, a = [0 0 1 0 1 0 1]. i have to transform it into n bit number, n = column number,
a = 0010101.
sprintf and other functions ignore the preceding zeros, which isn't helpful.

Answers (1)

Image Analyst
Image Analyst on 3 Jul 2021
Try this:
a = [0 0 1 0 1 0 1]
str = sprintf('%d', a)
num = bin2dec(str)
a =
0 0 1 0 1 0 1
str =
'0010101'
num =
21

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!