fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void printhex(float number)
  6. {
  7. // rozbijamy sobie ladnie na bajty
  8. unsigned char address[4];
  9. unsigned char * wtab = address ;
  10. // wyciagamy wartosci poszczegolnych bajtow do tablicy charow
  11. *(reinterpret_cast<float*>(wtab)) = number;
  12. for(int i=3;i>=0;i--) cout << hex << static_cast<int>(wtab[i]) << " ";
  13. cout << endl;
  14. }
  15.  
  16. int main()
  17. {
  18. printhex(5.0);
  19. printhex(1.0);
  20. printhex(-1.0);
  21. printhex(0.0);
  22. printhex(123.125);
  23. printhex(-345.0);
  24. return 0;
  25. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
40 a0 0 0 
3f 80 0 0 
bf 80 0 0 
0 0 0 0 
42 f6 40 0 
c3 ac 80 0