Convert an int into a byte arch

xiaoxiao2021-03-06  50

I have been working on transmitting JPEG's through sockets.In order to read each picture, I needed to know the number of bytes I too had to create int to byte [] and byte [] to int.Here is the code:. [Code ] / *** @Param ba * @ Return * / private int getintfrombytearray (byte [] ba) {INT i; if (Ba [0] <0) i = ba [0] 256; elsei = ba [0] i << = 8; IF (ba [1] <0) i = ba [1] 256; Elsei = ba [1]; i << = 8; if (ba [2] <0) i = Ba [2] 256; Elsei = ba [2]; I << = 8; IF (ba [3] <0) i = ba [3] 256; Elsei = ba [3]; Return I;} / *** @Param i * @ return / private byte [] getinttobyteaRray (int V) {byte b [] = new byte [4]; int i, shift; for (i = 0, shift = 24; i <4; i , shift - = 8) B

= (Byte) (0xFF & (V >> Shift); return b;} [/ code]

转载请注明原文地址:https://www.9cbs.com/read-116540.html

New Post(0)