1. Member
Join Date
Jun 2012
Location
India
Posts
5
Rep Power
0

## Assigning hexadecimal value to float

I know that it is possible to assign hexadecimal values to a float, but I don`t know how to do it.
Is this correct ?????
Java Code:
`float hex_test = 0x17.2`

2. Banned
Join Date
Jun 2012
Location
Beijing,China
Posts
34
Rep Power
0

## Re: Assigning hexadecimal value to float

Maybe you can't .
float hex_test = 17.2f ;

Ksharp

3. ## Re: Assigning hexadecimal value to float

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

4. ## Re: Assigning hexadecimal value to float

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.
Is this correct ?????
Java Code:
`float hex_test = 0x17.2`
Strange enough, the binary exponent part is mandatory here, so this is valid: 0x17.2p0

kind regards,

Jos

5. Member
Join Date
Jun 2012
Location
India
Posts
5
Rep Power
0

## Re: Assigning hexadecimal value to float

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.

6. ## Re: Assigning hexadecimal value to float

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

7. Member
Join Date
Jun 2012
Location
India
Posts
5
Rep Power
0

## Re: Assigning hexadecimal value to float

Thanks JosAH. Well explained !

8. Member
Join Date
Jun 2012
Location
India
Posts
5
Rep Power
0

## Re: Assigning hexadecimal value to float

Originally Posted by DarrylBurke
Very good for a detailed studying, Thanks

---
Ashiq