Convert int To Byte array by shifting right - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Convert int To Byte array by shifting right

Demo Code


//package com.java2s;

public class Main {
    public static byte[] intToBytes(int l) {
        byte[] result = new byte[4];
        for (int i = 3; i >= 0; i--) {
            result[i] = (byte) (l & 0xFF);
            l >>= 8;/* w  ww  .ja  v a 2s .  c o  m*/
        }
        return result;
    }
}

Related Tutorials