cout << &var; to binary??

How can I output the address of a variable in binary?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main()
{
    int x = 5;
    
    cout << &x << endl; // output binary not hex...HOW??
    
    return 0;
}
Last edited on
You can convert between bases easily, here's one method. Converting a hex string to a decimal string using stringstream and then converting to an unsigned integer.

http://www.cplusplus.com/reference/ios/hex/
SOLUTION IS HERE

http://www.cplusplus.com/forum/beginner/143174/
Last edited on
Topic archived. No new replies allowed.