Hi all,
Im having a lot of trouble adding an array of bytes containg a hexidecimal number to another in java. Here is an example of what I want to do (adding 2 byte arrays of hex):
00 00 00 FF
00 00 00 FF
-----------
00 00 01 FE
Here is what I have so far:
This comes out with 00 00 00 FE (using util methods to make the byte array readable as hex). Which is almost right, obviously im missing the overflow. I have no idea how I could detect this in Java, extensive googling has turned up nothing.Code:byte[] ary1 = new byte[]{(byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF}; byte[] ary2 = new byte[]{(byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF}; for (int i = 0; i < ary1.length; i++) { ary1[i] += ary2[i]; }
Or maybe there is another simpler way to go about this?
please help!


Reply With Quote


Bookmarks