fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. void binaryDump(T num, T mask)
  6. {
  7. if (mask)
  8. {
  9. cout << ((num&mask) ? "1" : "0");
  10. binaryDump(num, abs(mask >> 1));
  11. }
  12. else
  13. cout << endl;
  14. }
  15.  
  16. int main() {
  17. union {
  18. float flt;
  19. long lng;
  20. } x;
  21. union {
  22. double dbl;
  23. long long lng;
  24. } y;
  25.  
  26. cin >> x.flt;
  27. cout << x.flt << " is\n31 23 15 7 0" << endl;
  28. binaryDump(x.lng, 1L << 31);
  29.  
  30. cout << endl;
  31.  
  32. cin >> y.dbl;
  33. cout << y.dbl << " is\n63 55 47 39 31 23 15 7 0" << endl;
  34. binaryDump(y.lng, 1LL << 63);
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 3432KB
stdin
-125.635
123.4567
stdout
-125.635 is
31      23      15      7      0
11000010111110110100010100011111

123.457 is
63      55      47      39      31      23      15      7      0
0100000001011110110111010011101010010010101000110000010101010011