INT and BYTE array conversion

xiaoxiao2021-03-06  64

INTE array of int conversion has a length of 4, a BYTE number of length 4 is combined into an int.

Static int Bytes2int (byte [] b)

{

// Byte [] b = new byte [] {1, 2, 3, 4};

INT MASK = 0xFF;

INT TEMP = 0;

INT RES = 0;

For (int i = 0; i <4; i ) {

RES << = 8;

Temp = b [i] & mask;

RES | = TEMP;

}

Return res;

}

Static Byte [] INT2BYTES (INT NUM) {byte [] b = new byte [4]; // int mask = 0xff; for (int i = 0; i <4; i ) {b [i] = (Byte) (NUM >>> (24-i * 8));} RETURN B;}

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

New Post(0)