How do i convert data to 2 bit hexadecimal using num2hex?

6 次查看(过去 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
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by