Now, I could be wrong here, but this is what I'm thinking:

Code:
unsigned long G = B >> 8;  //256
unsigned long R = G >> 16; //65536
This shifts it too far... Instead of shifting 8 bits to get the green channel, and then another 8 to get the red channel, you're shifting 8 to get the green channel, and then 24 (2^8 * 2^16)...

I think it might work if you do this:

Code:
unsigned long G = B >> 8;  //256
unsigned long R = B >> 16; //65536