Advertisement
Guest User

Untitled

a guest
May 24th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <bitset>
  4. #include <cstdint>
  5.  
  6. std::string toBinaryString(double value)
  7. {
  8.    union
  9.    {
  10.       double d;
  11.       uint64_t i;
  12.    } u;
  13.    u.d = value;
  14.    std::bitset<64> b(u.i);
  15.    return b.to_string();
  16. }
  17.  
  18. int main(int argc, char* argv[])
  19. {
  20.    double value = 123.456;
  21.    std::cout << toBinaryString(value) << std::endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement