cout << &var; to binary??

Sep 24, 2014 at 2:25am
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 Sep 24, 2014 at 2:52am
Sep 24, 2014 at 2:37am
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/
Sep 24, 2014 at 2:56am
SOLUTION IS HERE

http://www.cplusplus.com/forum/beginner/143174/
Last edited on Sep 24, 2014 at 4:18am
Topic archived. No new replies allowed.