variable-length word builder
Could someone please help me find out why this doesn't work. It supposed to build multi-byte values with variable byte lengths. Positive values below 64 bits work, but not negative values.
int byteSize = whatever;
int bitSize = whatever;
byte[] buffer =newbyte[byteSize];
soure.readFully(buffer);//I know I'm getting all the data, 'cause it would
//throw an EOFException
// reverses buffer if not right endianness (needs to be Big)
long word = 0;
for (int x = 0; x< byteSize; ++x)
word += (buffer[x] & 0xFF) << ((byteSize - 1 - x) * 8);
return word;
I know the source works, and the changing of endianness works, but the reconstructor doesn't work with negative or >56bit words.
I don't know exactly how the Java system of handling signed values works, I just deduced this code from something else I saw.

