MATLAB: R2012b convert HEX to binary and extract individual bits

binary bitshex2bin

I have a data set that is output in HEX. I know how to convert the HEX to binary, even though in the R2012b release it's kinda convoluted.
>> DecimalNumber = hex2dec(X) %Where my HEX number is 4 digits in length 1-F in value for each digit
>> BinaryNumber = dec2bin(DecimalNumber,16) %giving me all 16 binary digits even when there are leading zero's
What I want to do is then break this into bit segments where I would get:
bits 1-5
bit 6
bits 7-11
bits 12-16
This will allow me to take my status word and see what the data is doing and what kinds of errors, if any, it are being reported out. I haven't been able to figure out a way to do this. Does anyone have any suggestions?

Best Answer

Is this all you are trying to do?
bits01_05 = bin2dec(BinaryNumber(1:5));
bits06_06 = bin2dec(BinaryNumber(6:6));
bits07_11 = bin2dec(BinaryNumber(7:11));
bits12_16 = bin2dec(BinaryNumber(12:16));