Hi, I am trying to read 4 bytes from a file using the DataInputStream, but I am not getting the correct integer back. If I use the readInt() method, I get -8355712 which is what I am expecting, but if I use readByte() 4 times and do some bit shifting and addition, I get -25198720, which is wrong. You may wonder why I just don't use readInt(), but believe me the other way is what I need in my special case.
Does anyone have some insight as to why this does not work?
Yes - readByte() returns a byte, in the range -128 to +127. If this is negative, then when you convert it to int, it acquires 1's in the first 12 bits. These screw you up when you combine the parts as you do. Try someting like