long to bytes - Java java.lang

Java examples for java.lang:long

Description

long to bytes

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        long i = 2;
        System.out.println(java.util.Arrays.toString(long2bytes(i)));
    }// w  ww  .  j av a2  s.  co m

    private static byte[] long2bytes(long i) {
        byte[] b = new byte[8];
        for (int m = 0; m < 8; m++, i >>= 8) {
            b[7 - m] = (byte) (i & 0x000000FF);
        }
        return b;
    }
}

Related Tutorials