I'm writing code to translate machine code. readFiveBytes is inside of a loop and supposed to take one byte at a time and place each byte into its correct place and return an address in the end.
void readFiveBytes(int c) {
if (counter != 0) {
currentIns = currentIns | (c << (counter * 4));
printf("reading byte: %X; address: %08X; counter: %d; type: 5\n",c, currentIns, counter);
counter = counter - 2;
} else {
currentIns = currentIns | c;
printType3(currentIns);
printf("reading byte: %X; address: %08X; counter: %d; type: 5\n",c, currentIns, counter);
currentIns = 0x00000000000000;
isFinishReading = true;
}
}
the output is
reading byte: 71; address: 00000071; counter: 8; type: 5
reading byte: 26; address: 26000071; counter: 6; type: 5
reading byte: 0; address: 26000071; counter: 4; type: 5
reading byte: 0; address: 26000071; counter: 2; type: 5
reading byte: 0; address: 26000071; counter: 0; type: 5
I'm wondering why the first byte has not been shifted to the most left? (It seems like second one is working well)