# Assigning hexadecimal value to float

• 06-20-2012, 07:26 AM
kashiqirphan
I know that it is possible to assign hexadecimal values to a float, but I don`t know how to do it:frusty:.
Is this correct ?????
Code:

`float hex_test = 0x17.2`
• 06-20-2012, 07:58 AM
Ksharp
Re: Assigning hexadecimal value to float
Maybe you can't .
float hex_test = 17.2f ;

Ksharp
• 06-20-2012, 10:28 AM
DarrylBurke
Re: Assigning hexadecimal value to float
Quote:

Originally Posted by Ksharp
Maybe you can't .

You can. You do need the type suffix though.

Chapter*3.*Lexical Structure
https://blogs.oracle.com/darcy/entry...point_literals

db
• 06-20-2012, 12:52 PM
JosAH
Re: Assigning hexadecimal value to float
Quote:

Originally Posted by kashiqirphan
I know that it is possible to assign hexadecimal values to a float, but I don`t know how to do it:frusty:.
Is this correct ?????
Code:

`float hex_test = 0x17.2`

Strange enough, the binary exponent part is mandatory here, so this is valid: 0x17.2p0

kind regards,

Jos
• 06-20-2012, 01:44 PM
kashiqirphan
Re: Assigning hexadecimal value to float
Quote:

Originally Posted by JosAH
Strange enough, the binary exponent part is mandatory here, so this is valid: 0x17.2p0

kind regards,

Jos

Does the "p0" suffix represent the exponent part ?
I found this in a book 0x12.2p2 is equal to 72.5(decimal), but the book does not explain the conversion, Can you explain please.
• 06-20-2012, 01:55 PM
JosAH
Re: Assigning hexadecimal value to float
Quote:

Originally Posted by kashiqirphan
Does the "p0" suffix represent the exponent part ?
I found this in a book 0x12.2p2 is equal to 72.5(decimal), but the book does not explain the conversion, Can you explain please.

Yep, the (decimal) number following the 'p' is the binary exponent. Your example: 12.2p2 means 18 (12 hexadecimal) + 2/16 (the part to the right of the decimal dot) multiplied by 2^2 (the binary exponent); that makes 72.5

kind regards,

Jos
• 06-20-2012, 03:20 PM
kashiqirphan
Re: Assigning hexadecimal value to float
Thanks JosAH. Well explained !
• 06-20-2012, 03:27 PM
kashiqirphan
Re: Assigning hexadecimal value to float
Quote:

Originally Posted by DarrylBurke

Very good for a detailed studying, Thanks

---
Ashiq