I am computing a checksum over a packet with byte sum = 0;. Writing sum = sum + data[i]; fails to compile with "incompatible types: possible lossy conversion from int to byte". Writing sum += data[i]; compiles and runs. Both operands are of type byte, so where does the int come from, and why is one form accepted?
I also get strange output when printing bytes: a received value of 0xF0 prints as -16, and (b >> 4) gives -1 instead of 15. How should byte arithmetic be written for protocol code?




