For the `getoctets()`

function, I first split the string, convert them into int and then add them to the byte array. However, when I try to do it like this

`bytearray[index]=(byte) integerform`

I get a signed representation of the integers, how do I get an unsigned version?

You can use the magnifier in the top right to search for topics.

A byte is interpreted as twoâ€™s complement per default.
As the comments say, you have to interpret bytes in an unsigned way.
No.
A byte in Java is a sequence of 8 bits. When doing arithmetic on these, Java says that the results are consistent with a twoâ€™s complement interpretation of the byte as a number. So if a represents A in twoâ€™s complement, and b represents B in twoâ€™s complement, then a+b represents A+B in twoâ€™s complement, if it is representable.
For example, if A = -4, then a = 0b11111100, and if B = 3, then b = 0b00000011, so a+b = 0b11111111, as A + B = -1. This should be obvious.
However, here we do not â€¦

This is where youâ€™re wrong: Yo do not get any â€śrepresentationâ€ť of integers. You get 8 bits, how they are interpreted is up to the programmer.

1 Like