Convert Decimal to Binary Vector

前端 未结 4 790
暗喜
暗喜 2021-01-05 01:13

I need to convert a Decimal Number to a Binary Vector

For example, Something like this:

  length=de2bi(length_field,16);

Unfortunat

4条回答
  •  执笔经年
    2021-01-05 02:11

    You mention not being able to use the function de2bi, which is likely because it is a function in the Communications System Toolbox and you don't have a license for it. Luckily, there are two other functions that you can use that are part of the core MATLAB toolbox: BITGET and DEC2BIN. I generally lean towards using BITGET since DEC2BIN can be significantly slower when converting many values at once. Here's how you would use BITGET:

    >> Data = 12;                  %# A decimal number
    >> Bin_Vec = bitget(Data,1:6)  %# Get the values for bits 1 through 6
    
    Bin_Vec =
    
         0     0     1     1     0     0
    

提交回复
热议问题