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

Android examples for File Input Output:Byte Array Convert

Description

Convert long To Byte array by shifting right

Demo Code


//package com.java2s;

public class Main {
    public static byte[] longToBytes(long l) {
        byte[] result = new byte[8];
        for (int i = 7; i >= 0; i--) {
            result[i] = (byte) (l & 0xFF);
            l >>= 8;/*from   w w w  . j a  v a2s.c  o  m*/
        }
        return result;
    }
}

Related Tutorials