Question

I'm tryin to mask an address in c++. This is what i've tried.

INT32 * myaddr = (INT32*)addr; // This converted 'addr' to the hexadecimal format -- 'myaddr'

Now how do I and it 0xff00 ?

UINT32 sec_addr = (myaddr & 0xff);

When I try to do the following.. This is the error I get:

error: invalid operands of types ‘LEVEL_BASE::INT32*’ and ‘int’ to binary ‘operator&’

What is the mistake i'm doing?

Was it helpful?

Solution

You are operating a pointer with an integer. Use the original addr variable, which is an integer, instead of myaddr:

UINT32 sec_addr = addr & 0xff; // according to your question, this should be 0xFF00

BTW: your first line:

INT32 * myaddr = (INT32*)addr; // This converted 'addr' to the hexadecimal format -- 'myaddr'

doesn't convert addr into "hexadecimal format". Hexadecimal is just a way to represent the number when you print it. Both addr and myaddr can be showed into whatever numeric base you want.

printf ("%d %X\n", addr, addr);

prints the value of addr in both decimal and hexadecimal format.

OTHER TIPS

First line should be

INT32 myaddr = (INT32)addr;

Assuming you are on a 32-bit platform.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top