# Get bytes from a short long in C18

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?

• a byte is 0xff long not 0x0f. Anyways, this is a nice example where it comes in handy to look at the generated assembly code. – jippie Apr 13 '13 at 15:22
• @jippie thanks, miscopied that from my code. Fixed now. – user17592 Apr 13 '13 at 15:22
• @Camil You're right, my bad. – m.Alin Apr 13 '13 at 15:22
• The code calls doSomething three times, first with the highest byte, second with the middle byte, and third with the lowest byte. – Pete Becker Apr 13 '13 at 15:25
• @PeteBecker thanks, that's what I wanted to hear - can you make it an answer? – user17592 Apr 13 '13 at 15:26

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