Java Long to Byte Array longToBytes(long v, byte[] b)

Here you can find the source of longToBytes(long v, byte[] b)

Description

long To Bytes

License

Open Source License

Declaration

public final static void longToBytes(long v, byte[] b) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004,2009 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*w  w  w.j a v a 2s.c  o  m*/
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

public class Main {
    public final static void longToBytes(long v, byte[] b) {
        assert b.length >= 8;
        b[0] = (byte) ((v >>> 56) & 0xFF);
        b[1] = (byte) ((v >>> 48) & 0xFF);
        b[2] = (byte) ((v >>> 40) & 0xFF);
        b[3] = (byte) ((v >>> 32) & 0xFF);
        b[4] = (byte) ((v >>> 24) & 0xFF);
        b[5] = (byte) ((v >>> 16) & 0xFF);
        b[6] = (byte) ((v >>> 8) & 0xFF);
        b[7] = (byte) ((v >>> 0) & 0xFF);
    }

    public final static void longToBytes(long v, byte[] b, int off) {
        assert b.length - off >= 8;
        b[off++] = (byte) ((v >>> 56) & 0xFF);
        b[off++] = (byte) ((v >>> 48) & 0xFF);
        b[off++] = (byte) ((v >>> 40) & 0xFF);
        b[off++] = (byte) ((v >>> 32) & 0xFF);
        b[off++] = (byte) ((v >>> 24) & 0xFF);
        b[off++] = (byte) ((v >>> 16) & 0xFF);
        b[off++] = (byte) ((v >>> 8) & 0xFF);
        b[off] = (byte) ((v >>> 0) & 0xFF);
    }
}

Related

  1. longToBytes(long num)
  2. longToBytes(long num, byte[] data, int index)
  3. longToBytes(long number)
  4. longToBytes(long v)
  5. longToBytes(long v)
  6. longToBytes(long v, byte[] bytes)
  7. longToBytes(long v, final byte[] arr)
  8. longToBytes(long val)
  9. longToBytes(long val)