Java Byte Array Create toByteArray(long value)

Here you can find the source of toByteArray(long value)

Description

to Byte Array

License

Open Source License

Declaration

public static byte[] toByteArray(long value) 

Method Source Code

//package com.java2s;
/*/*ww  w.j  a v  a 2  s . co m*/
 * Copyright (c) 2015, Antonio Gabriel Mu?oz Conejo <antoniogmc at gmail dot com>
 * Distributed under the terms of the MIT License
 */

public class Main {
    public static byte[] toByteArray(long value) {
        byte[] b = new byte[Long.BYTES];
        for (int i = 0; i < b.length; ++i) {
            b[i] = (byte) (value >> (Long.BYTES - i - 1 << 3));
        }
        return b;
    }

    public static byte[] toByteArray(int value) {
        byte[] b = new byte[Integer.BYTES];
        for (int i = 0; i < b.length; ++i) {
            b[i] = (byte) (value >> (Integer.BYTES - i - 1 << 3));
        }
        return b;
    }
}

Related

  1. toByteArray(int[] array)
  2. toByteArray(int[] data)
  3. toByteArray(int[] data, boolean includeLength)
  4. toByteArray(long hi, long lo)
  5. toByteArray(Long mac)
  6. toByteArray(long value)
  7. toByteArray(Number[] array)
  8. toByteArray(Object obj)
  9. toByteArray(Object value)