How do i convert data to 2 bit hexadecimal using num2hex?
9 ビュー (過去 30 日間)
古いコメントを表示
I am using num2hex where i am getting 8 bit as the output, i need to convert it to 2 bit. is there any way for that using num2hex? example :ffc00000, this is the output of 8 bit, how do i convert it to 2 bit?
15 件のコメント
Jan
2017 年 8 月 1 日
@Tousif Ahmed: Are you sure that the conversion from floating point zo 8 bit is useful? Why don't you use the floating point values directly? E.g. integer values from 0 to 255 or even a scalar UINT8 might be easier.
Stephen23
2017 年 8 月 3 日
See also this almost identical question:
回答 (1 件)
Walter Roberson
2017 年 7 月 31 日
LUT{'0'} = {'00' '00'};
LUT{'1'} = {'00', '01'};
LUT{'2'} = {'00', '10'};
LUT{'3'} = {'00', '11'};
LUT{'4'} = {'01', '00'};
LUT{'5'} = {'01', '01'};
LUT{'6'} = {'01', '10'};
LUT{'7'} = {'01', '11'};
LUT{'8'} = {'10' '00'};
LUT{'9'} = {'10', '01'};
LUT{'A'} = {'10', '10'};
LUT{'B'} = {'10', '11'};
LUT{'C'} = {'11', '00'};
LUT{'D'} = {'11', '01'};
LUT{'E'} = {'11', '10'};
LUT{'F'} = {'11', '11'};
LUT{'a'} = {'10', '10'};
LUT{'b'} = {'10', '11'};
LUT{'c'} = {'11', '00'};
LUT{'d'} = {'11', '01'};
LUT{'e'} = {'11', '10'};
LUT{'f'} = {'11', '11'};
hex = num2hex(single(ScalarValue));
output = [LUT{hex}];
The output would be, for example,
{'11' '11' '11' '11' '11' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00'}
You were not clear on what value you wanted for each output. If you want numeric values such as 0, 1, 2, 3 then you can code those instead of the '10' or whatever.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!