Search code examples
c#32bit-64bitmemory-address

How can I check if a given address is 32-bit or 64-bit?


How can I check if the address value in a long variable is 32bit or 64bit

Example:

long a = 0x06000000
long b = 0x13FFF0000

How can I programmatically check the bitness of these addresses?


Solution

  • You can use an AND operation to check if any of the higher 32 bits are set. Assuming that you have ulong because addresses are not negative:

    if ((x & 0xFFFFFFFF00000000UL) == 0)
        Console.WriteLine("x would fit into 32 bit");