none
32bit vs 64bit bitwise operator difference. RRS feed

  • Question

  • Greetings.

    I recently started compiling some old 32bit code under VS2010 64bit for the first time and got some perplexing errors which I traced to the following lines.

     

       LPARAM lparam = item.lParam;
       return ((int)(((lparam << 8 ) >> 24) & 0xFFFF));

    When the value of lparam is 16842752 (don't ask) the 32bit version returns 1, but the 64bit version returns 257.

    If I change it to the following...

       ULONG ulong = item.lParam;
       return ((int)(((ulong << 8 ) >> 24) & 0xFFFF));

    ... then I get 1 in both versions. I came up with the change by way of a wild guess that it had something to do with the sign bit, but I really have no idea what.

    Does anyone have any clues?

    Tuesday, December 20, 2011 5:28 AM

Answers

  • You do realize that LPARAM in 32-bit programs is 32 bits,
    while in 64-bit programs it's 64 bits?

    In both 32-bit and 64-bit programs a ULONG is 32 bits.

    - Wayne
    Tuesday, December 20, 2011 8:12 AM

All replies

  • You do realize that LPARAM in 32-bit programs is 32 bits,
    while in 64-bit programs it's 64 bits?

    In both 32-bit and 64-bit programs a ULONG is 32 bits.

    - Wayne
    Tuesday, December 20, 2011 8:12 AM
  • Doh! I didn't realise that, although of course I should have.

    Which would mean, obviously, that during the shift operations some of the bits don't get removed like they're supposed to.

    Thanks Wayne.

    Tuesday, December 20, 2011 9:35 AM