Convert int To Byte Array - Android java.lang

Android examples for java.lang:Integer

Description

Convert int To Byte Array

Demo Code

public class Main{

    public static byte[] intToByte(int i) {
        byte[] bt = new byte[4];
        bt[0] = (byte) (0xff & i);
        bt[1] = (byte) ((0xff00 & i) >> 8);
        bt[2] = (byte) ((0xff0000 & i) >> 16);
        bt[3] = (byte) ((0xff000000 & i) >> 24);
        return bt;
    }/*from w  w w  . j  a va2 s  .com*/

}

Related Tutorials