필터 지우기
필터 지우기

How do i convert decimal to hexadecimal for floating points

조회 수: 19 (최근 30일)
Tousif Ahmed
Tousif Ahmed 2017년 7월 19일
댓글: Victor Tamino 2021년 8월 27일
I have attached the screenshots, in which i have extracted HOG features for a image and found its values in floating point but when i am converting the same decimal values to hexadecimal i am getting the error. please help
  댓글 수: 8
Guillaume
Guillaume 2017년 7월 24일
@Walter,
As far as I know, all Xilinx FPGAs support single precision (and half-precision) floating-point (but not double). I commonly use single precision for some operations on my national instruments c-rio fpgas (programmed in labview). It does use a ton of gate and requires a lot more clock cycles than fixed-point though.

댓글을 달려면 로그인하십시오.

채택된 답변

David Goodmanson
David Goodmanson 2017년 7월 19일
HI Tousif,
try num2hex.
  댓글 수: 6
Tousif Ahmed
Tousif Ahmed 2017년 7월 31일
how it can be changed to 8 bit from 32 bit?
Walter Roberson
Walter Roberson 2018년 10월 25일
reshape((dec2bin(typecast(single(pi), 'uint8')) - '0').', 1, [])
Note that this would be in little-endian order. You might prefer
reshape((dec2bin(typecast(swapbytes(single(pi)), 'uint8')) - '0').', 1, [])

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

mansour torabi
mansour torabi 2021년 2월 18일
You can simply write your own floating point to hex converter, like the following:
x = 5329.675; % Floating point number
xI = floor(x); % Integer Part
HI = dec2hex(xI); % Integer Part in Hex
xF = x - xI; % Floating part
HF = ''; % Floating part in Hex (begining)
ii = 0;
while xF > 0
ii = ii + 1;
ff = xF * 16^ii;
II = floor(ff);
HF = [HF, dec2hex(II)];
xF = ff - II;
end
x_hex = [HI,'.',HF] % Concatinate both Integer and Floating Part in HEX format
  댓글 수: 1
Victor Tamino
Victor Tamino 2021년 8월 27일
Unfortunately, this code works with errors. If we try to convert 0.45619303 answer is: '0.74C911835D980', but correct answer is 0.74C91100835D98. And another example: 0.38574379 -> '0.62C1AE2AF622C0', but correct answer is 0.62C01AE2AF622DC. As we can see, your function loses zeros in the hex fractional part.
Where is the mistake? I can't understand.

댓글을 달려면 로그인하십시오.


Giancarlo Soasti
Giancarlo Soasti 2018년 10월 25일
dec2hex is the function you are probably looking for
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 10월 25일
No, dec2hex only works on nonnegative integers. If you look at the images the original poster posted, they need to convert floating point numbers including fractions.
Giancarlo Soasti
Giancarlo Soasti 2018년 10월 26일
Yep. You are right. I should have paid attention to the images.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by