Integer array to binary array

前端 未结 3 2077
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 09:45

I have an integer array:

a=[3,4,5,6,7];

I want to convert it to a binary array with four bits each. For the above integer array I would lik

3条回答
  •  攒了一身酷
    2020-12-30 09:50

    You can use the BITGET function:

    abinary = [bitget(a,4); ...  %# Get bit 4 for each number
               bitget(a,3); ...  %# Get bit 3 for each number
               bitget(a,2); ...  %# Get bit 2 for each number
               bitget(a,1)];     %# Get bit 1 for each number
    abinary = abinary(:)';      %'# Make it a 1-by-20 array
    

提交回复
热议问题