So, I had to take a test for a job interview where I was required to write a mini app that performed simple XOR encryption, and came across this question. I used a FileInputReader to pull each byte in, perform an XOR operation with the key, and pushed the result back out a FileOutputStream. Heres what got me thinking.
FileInputStream returns an int, a 32-bit signed type. When receiving only one byte, you can cast it into a 'byte' type. FileInputStream also returns -1 if it reaches EOF. But, -1 == 0xff in two's complement binary, so what if the byte read is really 0xff, not EOF?
Is 0xff a byte that mathematically won't ever be returned except in special cases (such as EOF)? Or is this a situation that you may have to account for depending on the data you are reading?