Java Byte Array Create toBytes(long v, byte[] writeBuffer, int o)

Here you can find the source of toBytes(long v, byte[] writeBuffer, int o)

Description

to Bytes

License

Open Source License

Declaration

public static byte[] toBytes(long v, byte[] writeBuffer, int o) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] toBytes(long v, byte[] writeBuffer, int o) {
        writeBuffer[o + 0] = (byte) (v >>> 56);
        writeBuffer[o + 1] = (byte) (v >>> 48);
        writeBuffer[o + 2] = (byte) (v >>> 40);
        writeBuffer[o + 3] = (byte) (v >>> 32);
        writeBuffer[o + 4] = (byte) (v >>> 24);
        writeBuffer[o + 5] = (byte) (v >>> 16);
        writeBuffer[o + 6] = (byte) (v >>> 8);
        writeBuffer[o + 7] = (byte) (v >>> 0);
        return writeBuffer;
    }/*from   w  w w . j  ava 2  s  .  c  o  m*/

    public static byte[] toBytes(long v, byte[] writeBuffer) {
        return toBytes(v, writeBuffer, 0);
    }

    public static byte[] toBytes(long v) {
        byte[] writeBuffer = new byte[8];
        return toBytes(v, writeBuffer, 0);
    }

    public static byte[] toBytes(long[] v, byte[] writeBuffer, int o) {
        for (int i = 0; i < v.length; i++)
            toBytes(v[i], writeBuffer, o + i * 8);
        return writeBuffer;
    }

    public static byte[] toBytes(long[] v) {
        byte[] writeBuffer = new byte[8 * v.length];
        return toBytes(v, writeBuffer, 0);
    }

    public static byte[] toBytes(int v, byte[] writeBuffer, int o) {
        writeBuffer[o + 0] = (byte) (v >>> 24);
        writeBuffer[o + 1] = (byte) (v >>> 16);
        writeBuffer[o + 2] = (byte) (v >>> 8);
        writeBuffer[o + 3] = (byte) (v >>> 0);
        return writeBuffer;
    }

    public static byte[] toBytes(int v) {
        byte[] writeBuffer = new byte[4];
        return toBytes(v, writeBuffer, 0);
    }

    public static byte[] toBytes(int[] v, byte[] writeBuffer, int o) {
        for (int i = 0; i < v.length; i++)
            toBytes(v[i], writeBuffer, o + i * 4);
        return writeBuffer;
    }

    public static byte[] toBytes(int[] v) {
        byte[] writeBuffer = new byte[4 * v.length];
        return toBytes(v, writeBuffer, 0);
    }

    public static byte[] toBytes(short v, byte[] writeBuffer, int o) {
        writeBuffer[o + 0] = (byte) (v >>> 8);
        writeBuffer[o + 1] = (byte) (v >>> 0);
        return writeBuffer;
    }

    public static byte[] toBytes(short v) {
        byte[] writeBuffer = new byte[2];
        return toBytes(v, writeBuffer, 0);
    }

    public static byte[] toBytes(short[] v, byte[] writeBuffer, int o) {
        for (int i = 0; i < v.length; i++)
            toBytes(v[i], writeBuffer, o + i * 2);
        return writeBuffer;
    }

    public static byte[] toBytes(short[] v) {
        byte[] writeBuffer = new byte[2 * v.length];
        return toBytes(v, writeBuffer, 0);
    }
}

Related

  1. toBytes(long l, byte[] bytes, int offset, int limit)
  2. toBytes(long lp)
  3. toBytes(long n)
  4. toBytes(long number)
  5. toBytes(long size)
  6. toBytes(long val)
  7. toBytes(long value)
  8. toBytes(long value)
  9. toBytes(long value)