Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I'm floating integer to hex?

I'm floating integer to hex?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BOBOBOBOBS
    wrote on last edited by
    #1

    Alright...this is a small part of a problem I'm doing for C++ class..We have to store a floating integer T. T=1.5 . Now, we have to convert this stored value to hex...Kinda like this: float t; t = 1.5; std::hex << t << "\n"; Or whatever..You get the idea tho..store the value, and convert it to it's hex format. Have any suggestions?

    T M 2 Replies Last reply
    0
    • B BOBOBOBOBS

      Alright...this is a small part of a problem I'm doing for C++ class..We have to store a floating integer T. T=1.5 . Now, we have to convert this stored value to hex...Kinda like this: float t; t = 1.5; std::hex << t << "\n"; Or whatever..You get the idea tho..store the value, and convert it to it's hex format. Have any suggestions?

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      hello, i think you ar elooking for sprintf() function ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

      1 Reply Last reply
      0
      • B BOBOBOBOBS

        Alright...this is a small part of a problem I'm doing for C++ class..We have to store a floating integer T. T=1.5 . Now, we have to convert this stored value to hex...Kinda like this: float t; t = 1.5; std::hex << t << "\n"; Or whatever..You get the idea tho..store the value, and convert it to it's hex format. Have any suggestions?

        M Offline
        M Offline
        mirex
        wrote on last edited by
        #3

        depends how do you want to convert it to hex ... you know usually only ints are converted to hexes ... floating part is not carried over. You could do printf( "%X", (int) t ); to print it in hex, but it will print only integer part. If you want to print its binary representation you could do printf( "%08X", *((long*) &t) );

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups