Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Real Number from Bytes,

Status
Not open for further replies.

goldrold

Programmer
Jul 16, 2006
1
US
Greetings. I am trying to extract the real number from the bytes
Bit 15 is a sign bit , zero indicates positive number.
Bits 14 through 7 are excess 128 binary component.
Bits 6 through 0 and 31 through 16 are a normalized 24 -bit fraction with falling sinificance in that order. The most significant bit 6 isworth 1/4.
In the hex code also thay are C7 11 42 3A.
the integer values of individual bytes are -57 17 66 58 .
I wantto extract the real vaue.
-57 in binary ------- 11000111 < bits 31 to 24
17 in binary ------- 00010001 < bits 23 to 16>
66 in binary ------- 01000010 < bits 15 to 8 >
58 in binary ------- 00111010 < bits 7 to 0 >


As per the above format bit 15 is 0. So sign is 0.
exponent is from from 14 to 7 ---- 10000100 = -4 = 132( unsigned int )
so, excess exponent = 4;
and mantissa is
0111010 11000111 00010001 0 = 7.7041e+06
The number is

Sign * 2 ^^( 132-128 )* 1.f.

Where f is float of mantissa.

I am getting 77041 and I expect a value between 10 and 50.
I can code it if I know whether I had understood this correctly.
 
Have you tried type-casting the value? Why go to the trouble of duplicating what the compiler will already do for you?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top