Determining which flags are set from a hexadecimal input
显示 更早的评论
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
采纳的回答
更多回答(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.
类别
在 帮助中心 和 File Exchange 中查找有关 Just for fun 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!