Determining which flags are set from a hexadecimal input
Ältere Kommentare anzeigen
Hi,
I'm currently looking into writing a program which reads a hexadecimal input, and then tells me which flags are set depending on what the hex input is.
For e.g. input - hex = 0062
output - 'Byte 0 bit 1 is set' therefore parameter x - 'Byte 1 bit 0 is set' therefore parameter y - 'Byte 1 bit 3 is set' therefore parameter z
Could anyone assist in what the best way would be to program this code?
Thanks
Akzeptierte Antwort
Weitere Antworten (1)
Perhaps this helps:
Str = '0062';
Num = sscanf(Str, '%.2x'); % Or is it '%2x'? Or HEX2DEC()
for iByte = 1:2
Byte = Num(iByte);
for iBit = 0:7
value = bitget(Byte, iBit);
fprintf('Byte %d Bit %d: %d', iByte, iBit, value);
end
end
This does not hit the "therefore parameter x" part, but I do not understand this expression.
Kategorien
Mehr zu Just for fun finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!