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

조회 수: 7 (최근 30일)
Tousif Ahmed
Tousif Ahmed 2017년 7월 31일
댓글: Stephen23 2017년 8월 3일
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