Java Byte Array Create toByteArray(long hi, long lo)

Here you can find the source of toByteArray(long hi, long lo)

Description

converts two longs to a byte[]

License

Open Source License

Parameter

Parameter Description
hi long
lo long

Return

byte[]

Declaration

public static byte[] toByteArray(long hi, long lo) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w w  w.jav a 2s.  co  m
     * converts two longs to a byte[]
     *
     * @param hi long
     * @param lo long
     * @return byte[]
     */
    public static byte[] toByteArray(long hi, long lo) {

        byte[] bytes = new byte[16];
        int count = 0;
        int v;

        while (count < 16) {
            if (count == 0) {
                v = (int) (hi >>> 32);
            } else if (count == 4) {
                v = (int) hi;
            } else if (count == 8) {
                v = (int) (lo >>> 32);
            } else {
                v = (int) lo;
            }

            bytes[count++] = (byte) (v >>> 24);
            bytes[count++] = (byte) (v >>> 16);
            bytes[count++] = (byte) (v >>> 8);
            bytes[count++] = (byte) v;
        }

        return bytes;
    }
}

Related

  1. toByteArray(int value)
  2. toByteArray(int value, int numBytes, byte[] dest, int off)
  3. toByteArray(int[] array)
  4. toByteArray(int[] data)
  5. toByteArray(int[] data, boolean includeLength)
  6. toByteArray(Long mac)
  7. toByteArray(long value)
  8. toByteArray(long value)
  9. toByteArray(Number[] array)