hexa decimal problem

i am just messed up .. how can i store a hex no. as an adress of a varaible

e.g i got an integer value x i need to convert it into hexadecimal then need to make it an adress of a variable "a" so if i do cout<<&a it gives the adress i-e hex value of x

I don't understand what you want.

If you do std::cout << &a; the output should already be in hexedicimal, unless a is type char.

In which case you could use std::cout << static_cast<void*>(&a);
If you simply want to output an integer in hexedecimal then you can do this:

1
2
3
int i = 42768;

std::cout << std::hex << i;
i need to give a manual address to a specific variable
I am with Galik. I have no idea what you're trying to do. These should help you. Just put them together the way you need.

int x = 5; // value at x is equal to 5
int* xPtr = &x // value at xPtr is equal to the address of x
int* randomPtr = (int*)31582; // value at randomPtr is equal to 31582
int* anotherandomPtr = (int*)0x005C6600; // value at anotherrandomPtr is equal to 0x005C6600

Every variable is an address. x is an address that stores the value 5. xPtr is an address that stores the address of an integer, etc.

hexadecimal is simply another representation for a number. 0xF IS 15; they are the EXACT same thing.
Last edited on
zelin wrote:
i need to give a manual address to a specific variable


Then I think you need to do something like this:

 
int& i = *reinterpret_cast<int*>(0xbfa77c14);
Topic archived. No new replies allowed.