Jump to content

cbox


represent floating point as hexadecimal


Recommended Posts

Posted

hello :)

 

I wish to write a program, preferably in C# but possibly VB, that when you enter a floating point value it gives you the hexadecimal representation of the float, and when you enter a hexidecimal number, it shows it's value as a float.

 

E.g 0x41200000 is 10 as a float. But what is 0x41200001 as a float? I want my program to do work this out.

 

Only problem is, I don't know how to do this! :(

 

Could someone help me out? like provide bits of code or something?

 

Thanks :)

Posted

I have read up on IEEE 754 and sort of understand the math, but I don't know how to make a program do the math... :(

 

Is there a simple way of doing it?

 

Or maybe a class in C# that already does it?

Posted

Its on the page.

 

Conversion: The value of a IEEE-754 number is computed as:

sign * 2exponent * mantissa

The sign is stored in bit 32. The exponent can be computed from bits 24-31 by subtracting 127. The mantissa (also known as significand or fraction) is stored in bits 1-23. An invisible leading bit (i.e. it is not actually stored) with value 1.0 is placed in front, then bit 23 has a value of 1/2, bit 22 has value 1/4 etc. As a result, the mantissa has a value between 1.0 and 2. If the exponent reaches -127 (binary 00000000), the leading 1 is no longer used to enable gradual underflow.

 

Do you know how to set variables, use mod, the signs, etc?

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...