fork download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. int main() {
  6. float x;
  7. cout << "Podaj liczbe typu float: ";
  8. cin >> x;
  9.  
  10. // Rzutowanie pamięci float na 32-bitową liczbę całkowitą
  11. uint32_t bits = *reinterpret_cast<uint32_t*>(&x);
  12.  
  13. bitset<32> b(bits);
  14.  
  15. cout << "\nReprezentacja IEEE-754 (float, 32 bity):\n";
  16. cout << "Bity: " << b << endl;
  17. cout << "Znak: " << b[31] << endl;
  18. cout << "Wykladnik: " << b.to_string().substr(1, 8) << endl;
  19. cout << "Mantysa: " << b.to_string().substr(9, 23) << endl;
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5316KB
stdin
10.25
stdout
Podaj liczbe typu float: 
Reprezentacja IEEE-754 (float, 32 bity):
Bity:       01000001001001000000000000000000
Znak:       0
Wykladnik:  10000010
Mantysa:    01001000000000000000000