Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By DarrylBurke
  • 1 Post By JosAH

Thread: Assigning hexadecimal value to float

  1. #1
    kashiqirphan is offline Member
    Join Date
    Jun 2012
    Location
    India
    Posts
    5
    Rep Power
    0

    Question 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. #2
    Ksharp is offline Banned
    Join Date
    Jun 2012
    Location
    Beijing,China
    Posts
    34
    Rep Power
    0

    Default Re: Assigning hexadecimal value to float

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


    Ksharp

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Assigning hexadecimal value to float

    Quote Originally Posted by Ksharp View Post
    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
    kashiqirphan likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Assigning hexadecimal value to float

    Quote Originally Posted by kashiqirphan View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    kashiqirphan is offline Member
    Join Date
    Jun 2012
    Location
    India
    Posts
    5
    Rep Power
    0

    Exclamation Re: Assigning hexadecimal value to float

    Quote Originally Posted by JosAH View Post
    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. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Assigning hexadecimal value to float

    Quote Originally Posted by kashiqirphan View Post
    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
    kashiqirphan likes this.
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    kashiqirphan is offline Member
    Join Date
    Jun 2012
    Location
    India
    Posts
    5
    Rep Power
    0

    Default Re: Assigning hexadecimal value to float

    Thanks JosAH. Well explained !

  8. #8
    kashiqirphan is offline Member
    Join Date
    Jun 2012
    Location
    India
    Posts
    5
    Rep Power
    0

    Default Re: Assigning hexadecimal value to float

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

    ---
    Ashiq

Similar Threads

  1. Converting image to hexadecimal
    By abdique63 in forum New To Java
    Replies: 11
    Last Post: 04-26-2012, 12:02 PM
  2. How to convert a String into an Hexadecimal ?
    By ze snow in forum New To Java
    Replies: 7
    Last Post: 02-16-2010, 10:31 PM
  3. Returning HexaDecimal Values to an Array???
    By stylishkishore in forum Advanced Java
    Replies: 5
    Last Post: 12-18-2009, 08:04 AM
  4. Replies: 4
    Last Post: 04-08-2009, 05:51 AM
  5. Replies: 7
    Last Post: 01-12-2008, 09:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •