arrays - Efficient bit shuffling of vector of binary numbers -
i have recorded data containing vector of bit-sequences, re-arrange efficiently. 1 value in vector of data this:
bit0, bit1, bit2, ... bit7 i re-arrange bit-sequence order:
bit0, bit7, bit1, bit6, bit2, bit5, bit3, bit4 if had 1 value work nicely via:
sum(uint32(bitset(0,1:8,bitget(uint32(x), [1 8 2 7 3 6 4 5])))) unfortunately bitset , bitget not capable of handling vectors of bit-sequences. since have large dataset interested in efficient solutions.
any appreciated, thanks!
dec2bin , bin2dec can process vectors, can input numbers @ once , permute matrix:
input=1:23; pattern = [1 8 2 7 3 6 4 5]; bit=dec2bin(input(:),numel(pattern)); if size(bit,2)>numel(pattern) warning('input numbers large pattern, leading bits cut off') end output=bin2dec(bit(:,pattern)); if available, use de2bi , bi2de instead.
Comments
Post a Comment