Using reinterpret_cast: cast float to int : reinterpret_cast « Development « C++ Tutorial






#include <cassert>
#include <iomanip>
#include <iostream>
#include <ostream>

using namespace std;

int main()
{
  
  float pi = 1.1;
  int   ipi;

  cout << setfill('0') << showbase << hex << internal;

  assert(sizeof(int) == sizeof(float));
  ipi = reinterpret_cast<int&>(pi);
  cout << "pi bits=" << setw(10) << ipi << '\n';

}
pi bits=0x3f8ccccd








5.21.reinterpret_cast
5.21.1.Use reinterpret_cast to cast from char pointer to integer
5.21.2.Using reinterpret_cast: cast float to int