fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <bitset>
  4. using namespace std;
  5.  
  6. int main() {
  7. float x;
  8.  
  9. cout << "Podaj liczbe typu float: ";
  10. cin >> x;
  11.  
  12. // Interpretacja float jako 32-bitowej liczby całkowitej
  13. uint32_t bits = *reinterpret_cast<uint32_t*>(&x);
  14.  
  15. bitset<32> b(bits);
  16.  
  17. cout << "\nReprezentacja IEEE-754 (float, 32 bity):\n";
  18. cout << "Bity : " << b << "\n";
  19. cout << "Znak : " << b[31] << "\n";
  20. cout << "Wykladnik : " << b.to_string().substr(1, 8) << "\n";
  21. cout << "Mantysa : " << b.to_string().substr(9) << "\n";
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Podaj liczbe typu float: 
Reprezentacja IEEE-754 (float, 32 bity):
Bity       : 00000000000000000001010010111011
Znak       : 0
Wykladnik  : 00000000
Mantysa    : 00000000001010010111011