I'm trying to write a Chip8 emulator with java and I've come across a question with the readAllBytes
function in Java Files
. When I loaded the bytes from the ROM I'm using to test into the "memory" array of my emulator, I tried to print those bytes to see if they are going into the memory correctly. I used Integer.toHexString
to see those bytes as hex values and compare them to the actual file that I loaded with a hex editor, but the output that it gives me is strange:
First bytes of the file:
00 e0 a3 4c
Output from test:
0 ffffffe0 ffffffa3 4c
Code:
public void loadToMem(byte[] program) {
for(int i = 0; i < program.length; i++) {
this.memory[i+512] = program[i];
System.out.println(Integer.toHexString(this.memory[i+512]));
}
this.initializeComponents();
}
Those values are just an error in the representation that Integer.toHexString
gives and the values are being loaded correctly or are they really being loaded incorrectly? Why is it padding with f's?