How can I convert a binary to a decimal without using a loop?

前端 未结 3 1179
醉梦人生
醉梦人生 2020-12-03 16:02

I have a 12-bit binary that I need to convert to a decimal. For example:

A = [0,1,1,0,0,0,0,0,1,1,0,0];

Bit 1 is the most significant bit,

3条回答
  •  再見小時候
    2020-12-03 16:51

    If the MSB is right-most (I'm not sure what you mean by Bit 1, sorry if that seems stupid):

    Try:

    binvec2dec(A)
    

    Output should be:

     ans =
       774
    

    If the MSB is left-most, use fliplr(A) first.

提交回复
热议问题