Decimal to binary as double type array, not string

后端 未结 3 818
半阙折子戏
半阙折子戏 2020-12-07 03:15

I have this so far:

data = 14
out = dec2bin(data, 4)

which gives:

out = 1110

But I want to get binary num

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 04:00

    You're looking for de2bi with the 'left-msb' option.

    data = 14
    out = de2bi(data, 4,'left-msb')
    

    Which requires the Communication Systems Toolbox though. Alternatively use your original approach with the fundamental dec2bin with the following addition:

    data = 14
    out = double( dec2bin(data, 4) ) - 48
    

    out =
    
         1     1     1     0
    

提交回复
热议问题