Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert a number of type Long or Double into a byte array
How to convert a number of type Long or Double into a byte array
The following are the methods to convert Int Into byte array and byte array into int: the four bytes corresponding to int are:

Byte[] intBytes = new byte [4];

int bytes[0]=(byte)(x & gt; & gt24);

int bytes[ 1]=(byte)(x & gt; & gt 16);

int bytes[2]=(byte)(x & gt; & gt8);

int bytes[3]=(byte)(x & gt; & gt0);

And from byte to int, b3 corresponds to the above intBytes[0]:

Public static int makeInt (byte b3, byte b2, byte b 1, byte b0) {

return(int)((((B3 & amp; 0x ff)& lt; & lt24)|((B2 & amp; 0x ff)& lt; & lt 16)

|((b 1 & amp; 0x ff)& lt; & lt8)|((B0 & amp; 0x ff)& lt; & lt0)));

} Transforming into a long pair is also a change. .