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. How can I convert a hex string to float, and vice-versa.

How can I convert a hex string to float, and vice-versa.

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 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.
  • J Offline
    J Offline
    John Uhlenbrock
    wrote on last edited by
    #1

    Any ideas? ie. "4476976c"-hex is approximately 986.366-float

    T 1 Reply Last reply
    0
    • J John Uhlenbrock

      Any ideas? ie. "4476976c"-hex is approximately 986.366-float

      T Offline
      T Offline
      Tim Deveaux
      wrote on last edited by
      #2

      I know I'm doing something unnecessary here, but it is sunday morning after all... X|

      float a = 986.366;
      float \*b = &a;
      
      // this prints the bytes representing the float in mem
      for(int i = 0; i < sizeof(float); ++i ) 
      {
          printf("%2x", \*((unsigned char\*)b+i));
      }
      
      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