Java's byte type is signed, ranging from -128 to 127, which causes confusion when working with values like 170 that appear as -86. This post explains the fundamentals of bits and bytes, the difference between signed and unsigned numeric representation, and how to correctly convert byte values in Java using Byte.toUnsignedInt() and bitwise operations like value & 0xFF to retrieve the expected unsigned value.
Table of contents
The basicsConvert bits to a numeric and hex valueCalculate a byte valueValues in JavaSigned versus unsignedConclusionSort: