Clear Filters
Clear Filters

bitwise reading of a 8 bit binary number and assigning an indicator for every 2 bits

2 views (last 30 days)
i need to read a 53x1 table containing 8bit binary value and access them bitwise. the code i used is not reading from a table. i have to give each value as input manualy.how do i give a table as input and do the bitwise reading where every 2 bit in the 8 bit binary code is an indicator which i need to decode it to do analysis.
i need to read the table row by row in a loop. do bitwise reading. if the first 2 bit is 00 or 01 or 10 or 11 then print output in the same table(starting from the next column)such as inactive or active or undefined or not available respectively. similarly the next bits have to be read in the same way and print the result. this has to be done for eac each row. it would really helpful if anyone could help me out with this. thank you
the code i have used for hex to binary conversion are as follows. here also im unable to give a table as input for the conversion
fourth_column = {'0','0D','83','FF','1',}; %just specified few of the lines
fourth_column = hex2dec(fourth_column);
fourth_column = table(dec2bin(fourth_column,8));
%for bitwise reading i used
n = 10101010;
A= bitget(n,1:2);

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jan 2020
possible_statuses = {'inactive', 'active', 'undefined', 'not available'};
fourth_column = {'0','0D','83','FF','1',}; %just specified few of the lines
bits = dec2bin(hex2dec(fourth_column),8) - '0';
idx = bits(:,1:2:end)*2+bits(:,2:2:end)+1;
actual_statuses = possible_statuses(idx);
actual_statuses =
5×4 cell array
{'inactive' } {'inactive' } {'inactive' } {'inactive' }
{'inactive' } {'inactive' } {'not available'} {'active' }
{'undefined' } {'inactive' } {'inactive' } {'not available'}
{'not available'} {'not available'} {'not available'} {'not available'}
{'inactive' } {'inactive' } {'inactive' } {'active' }
which you can enter into the table as appropriate.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!