943,083 Members | Top Members by Rank

Ad:
Jan 17th, 2010
0

converting float to hexadecimal

Expand Post »
I am writing a program to implement this without using any built in function from C++. I am having some trouble figuring out how to find the decimal value and exponent for very small numbers like 0.25 0.15 0.0 etc. I need to convert my float to binary and then to hexadecimal because of my program spec.

From what I can understand to find out my exponent and decimal value for 32-bits hexadecimal, I convert the integer part of my float to binary, and its exponent is the number of digit - 1. Then my decimal value would be the offset 127 + the exponent. My decimal value in binary will be my exponent field and part of my 32 bits string.

This works only for large number, but for small numbers that requires negative exponent, I have no clue on how that works. Is there an easy systematic way that I can find this out?
Last edited by red999; Jan 17th, 2010 at 8:07 am.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
red999 is offline Offline
55 posts
since Jan 2009
Jan 17th, 2010
1
Re: converting float to hexadecimal
http://www.psc.edu/general/software/.../ieee/ieee.php
You subtract the offset from the exponent. A stored exponent of 128 say would map to a real exponent of 1. So fractions ultimately end up with negative real exponents (0.5 = 1 * 2^-1)

If you're able to extract the sign, exponent and mantissa bits, then the rest should be pretty easy. There is nothing irregular about fractions except for the magnitude of the exponent.
Team Colleague
Reputation Points: 5862
Solved Threads: 949
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Push Down Automata (PDA).
Next Thread in Computer Science Forum Timeline: what is the worst input for quick sort ??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC