MATLAB: Generate bitstream from matrix elements

bitstreamMATLABmatrix

with a 1xN vector whose elements are in the order from the least significant bit v(1) to the most significant bit v(N) , how can I put the elements together with this order in a bitstream?

Best Answer

vv = uint8(v);
out = vv(1:8:end) + uint8(2)*vv(2:8:end) + uint8(4)*vv(3:8:end) + uint8(8)*vv(4:8:end) + uint8(16)*vv(5:8:end) + uint8(32)*vv(6:8:end) + uint8(64)*vv(7:8:end)
It will be least significant byte first, so if you want most significant first, fliplr() the output.