Java Long to Byte Array longToBytes(long l, byte[] bytes, int offset)

Here you can find the source of longToBytes(long l, byte[] bytes, int offset)

Description

long To Bytes

License

Open Source License

Declaration

public static void longToBytes(long l, byte[] bytes, int offset) 

Method Source Code

//package com.java2s;
/*// w  w w .  j a  v  a 2 s  .c o m
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

public class Main {
    public static void longToBytes(long l, byte[] bytes, int offset) {
        bytes[offset + 0] = (byte) ((l & 0xFF00000000000000L) >> 56);
        bytes[offset + 1] = (byte) ((l & 0x00FF000000000000L) >> 48);
        bytes[offset + 2] = (byte) ((l & 0x0000FF0000000000L) >> 40);
        bytes[offset + 3] = (byte) ((l & 0x000000FF00000000L) >> 32);
        bytes[offset + 4] = (byte) ((l & 0x00000000FF000000L) >> 24);
        bytes[offset + 5] = (byte) ((l & 0x0000000000FF0000L) >> 16);
        bytes[offset + 6] = (byte) ((l & 0x000000000000FF00L) >> 8);
        bytes[offset + 7] = (byte) ((l & 0x00000000000000FFL));
    }
}

Related

  1. longToBytes(long l)
  2. longToBytes(long l)
  3. longToBytes(long l)
  4. longToBytes(long l, byte[] arr, int startIdx)
  5. longToBytes(long l, byte[] b)
  6. longToBytes(long l, byte[] data, int[] offset)
  7. longToBytes(long l, byte[] result)
  8. longToBytes(long ldata, int n)
  9. longToBytes(long lnum, byte[] bytes, int startIndex)