Convert Decimal to Binary Vector

前端 未结 4 789
暗喜
暗喜 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 01:56

    Are you using this for IEEE 802.11 SIGNAL field? I noticed "length_field" and "16". Anyway here's how I do it.

        function [Ibase2]= Convert10to2(Ibase10,n)
    
        % Convert the integral part by successive divisions by 2
        Ibase2=[];
    
    
        if (Ibase10~=0)
    
        while (Ibase10>0)
    
        q=fix(Ibase10/2);
        r=Ibase10-2*q;
        Ibase2=[r Ibase2];
        Ibase10=q;
        end
    
    
        else
        Ibase2=0;
        end
    
        o = length(Ibase2);
        % append redundant zeros
        Ibase2 = [zeros(1,n-o) Ibase2];
    

提交回复
热议问题