I'm following a tutorial to write an emulator for the Chip8. Opcodes are 2 bytes long and in HEX. They are stored in unsigned short data types (which is 2 bytes).
I want to get the last byte off of one of these shorts and save it on a char (1 byte).
I have tried using the & operation to filter out the first byte and then assign to a char variable.
unsigned short opcode = 0x56FA; //sample opcode
char mychar = opcode & 0x00FF; //& operation to make 1st byte zeros
printf("%02X \n", mychar); //should print last byte FA
I expect for it to print FA. but instead prints out FFFFFFFA.