If you have an array of Byte() class, then the class itself has an intValue() method that returns the value of this Byte as an int.
Read the javadocs for the Byte class for more details.
- More efficiently, just manually code it with shifts and ORs. You also generally have to be careful to AND each byte value with 0xff to remove the sign:
I don't know how else to explain, but this certainly was picked up by the original poster since he asked me the next question on that, which told us he wanted to convert the bytes to integer manually. My response to this post "then you need to write your own binary to decimal function" explains the next step without going into unecesary details, which as I mentioned should be left to the OP to be figured out.
Last edited by verruckt24; Jan 3rd, 2009 at 2:34 pm.
Ah, you mean convert each individual byte into an unsigned int. If that's really what the poster meant, then sorry -- I misinterpreted. But I think the poster means that they want to amalgamate the four bytes and get a single, four-byte integer value.
By the way, for converting a byte to an int, just ANDing with 0xff is common and efficient.
On pondering over it now, I feel, even I might have misinterpreted, cause this 4 bytes thing didn't cross my mind, I was of the notion that he wanted the integer value of each of them. Well, nevermind, the OP has both the solutions, he can choose the appropriate one. Cheers !!
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.