Javadoc
Allow a variable of type byte
to carry lengths or sizes up to 255.
The integral types are signed in Java, so if there is necessary to store
an unsigned type into signed of the same size, the value can be stored
as negative number even if it would be positive in unsigned case.
For example message length can be 0 to 254 and is carried by 1 octet
i.e. unsigned 8 bits. We use a byte variable to read the value from octet stream.
If the length is >127, it is interpreted as negative byte using negative
complement notation.
So length 150 would be interpreted as Java byte -106. If we want to know
the actual value (*length) we need to make a correction to a bigger integral type,
in case of byte it's short. The correction from (negative) byte to short is
(short)(256+(short)length)
This converts the negative byte value representing positive length into positive
short value.