Java Long to Byte Array long2byteArray(long k, byte b[], int off)

Here you can find the source of long2byteArray(long k, byte b[], int off)

Description

longbyte Array

License

Open Source License

Declaration

public static void long2byteArray(long k, byte b[], int off) 

Method Source Code

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

public class Main {
    public final static int LONG_BYTES = 8;

    public static void long2byteArray(long k, byte b[], int off) {
        int j;/*from w ww .  ja  v  a 2 s  . com*/

        j = b.length;
        if (b == null || j <= off) {
            return;
        }

        j -= off;
        if (j > LONG_BYTES) {
            j = LONG_BYTES;
        }

        switch (j) {
        case 8:
            b[off + 7] = (byte) ((k >> 56) & 0x0ff);
        case 7:
            b[off + 6] = (byte) ((k >> 48) & 0x0ff);
        case 6:
            b[off + 5] = (byte) ((k >> 40) & 0x0ff);
        case 5:
            b[off + 4] = (byte) ((k >> 32) & 0x0ff);
        case 4:
            b[off + 3] = (byte) ((k >> 24) & 0x0ff);
        case 3:
            b[off + 2] = (byte) ((k >> 16) & 0x0ff);
        case 2:
            b[off + 1] = (byte) ((k >> 8) & 0x0ff);
        case 1:
            b[off] = (byte) (k & 0x0ff);
        }
    }
}

Related

  1. long2byteArray(final long number, final int length, final boolean swapHalfWord)
  2. long2ByteArray(long l)
  3. long2ByteArray(long srcValue, int len)
  4. long2ByteLE(byte[] bytes, long value, int offset)
  5. long2bytes(long i)