fork download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. int main() {
  6. float x;
  7.  
  8. // Dla testów ustawiamy konkretne wartości:
  9. // a) 10.25
  10. // b) -0.2
  11. float values[] = {10.25f, -0.2f};
  12.  
  13. for (float x : values) {
  14. // Rzutowanie wskaźnika na 32-bitową liczbę całkowitą
  15. unsigned int bits = *reinterpret_cast<unsigned int*>(&x);
  16.  
  17. cout << "Liczba: " << x << endl;
  18. cout << "IEEE 754 (float, 32 bity): " << bitset<32>(bits) << endl;
  19. cout << endl;
  20. }
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Liczba: 10.25
IEEE 754 (float, 32 bity): 01000001001001000000000000000000

Liczba: -0.2
IEEE 754 (float, 32 bity): 10111110010011001100110011001101