0

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?

pistal
  • 2,310
  • 13
  • 41
  • 65

2 Answers2

2

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.

mcleod_ideafix
  • 11,128
  • 2
  • 24
  • 32
  • I don't think that's the case: `addr: 140737488345600` `sec_addr: 0` How can the sec_addr be 0? – pistal Apr 01 '14 at 08:48
  • My bad. I & with 255 then. now with 0xff00. :) – pistal Apr 01 '14 at 08:50
  • `140737488345600` is `7FFFFFFFDA00` in hex. `7FFFFFFFDA00 & 0000000000FF = 000000000000` – mcleod_ideafix Apr 01 '14 at 08:51
  • I've a problem that I can't convert from uint32 to void* invalid conversion from ‘LEVEL_BASE::UINT32’ to ‘const LEVEL_BASE::VOID*’ Here is my code: UINT32 sec_addr_main = addr & 0xff00; for(int i=0; i<4; i++) { UINT32 sec_addr = sec_addr_main + 64*i; – pistal Apr 01 '14 at 09:13
0

First line should be

INT32 myaddr = (INT32)addr;

Assuming you are on a 32-bit platform.

Eelke
  • 20,897
  • 4
  • 50
  • 76