fork download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. void showFloatBits(float x) {
  6. // Interpretujemy float jako 32-bitową liczbę
  7. uint32_t bits = *reinterpret_cast<uint32_t*>(&x);
  8.  
  9. bitset<32> b(bits);
  10.  
  11. cout << "Wartosc: " << x << endl;
  12. cout << "Bity: " << b << endl;
  13.  
  14. cout << "Znak: " << b[31] << endl;
  15. cout << "Cecha: " << b.to_string().substr(1, 8) << endl;
  16. cout << "Mantysa: " << b.to_string().substr(9) << endl;
  17. cout << "--------------------------------------\n";
  18. }
  19.  
  20. int main() {
  21. float a = 10.25f;
  22. float b = -0.2f;
  23.  
  24. showFloatBits(a);
  25. showFloatBits(b);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Wartosc: 10.25
Bity:    01000001001001000000000000000000
Znak:    0
Cecha:   10000010
Mantysa: 01001000000000000000000
--------------------------------------
Wartosc: -0.2
Bity:    10111110010011001100110011001101
Znak:    1
Cecha:   01111100
Mantysa: 10011001100110011001101
--------------------------------------