Get bytes from a short long in C18

cc18compilerpicsoftware

I'm using the C18 compiler and need to get the three bytes of a short long from MSB to LSB. I'd say I could use this:

void theFunction(unsigned short long input) {
    doSomething((input>>16) & 0xff);
    doSomething((input>>8) & 0xff);
    doSomething(input & 0xff);
}

But now my code isn't working (does compile, but doesn't run as expected). I do not know where the problem is, so can anyone confirm that this code works?

Best Answer

The code calls doSomething three times, first with the highest byte, second with the middle byte, and third with the lowest byte.