Java Long to longToFourBytes(long value)

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

Description

This function converts longToFourBytes

License

Open Source License

Parameter

Parameter Description
value long value

Exception

Parameter Description
Exception Exception

Return

value byte value

Declaration

public static final byte[] longToFourBytes(long value) throws Exception 

Method Source Code

//package com.java2s;
/*//  ww  w.j  a  va2s  .c  o m
 * Copyright (c) 2016 Tata Consultancy Services and others.  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
 */

public class Main {
    /**
     * This function converts longToFourBytes
     * 
     * @param value
     *            long value
     * @return value byte value
     * @throws Exception
     *             Exception
     */
    public static final byte[] longToFourBytes(long value) throws Exception {
        byte[] result = new byte[4];
        result[0] = (byte) ((value >>> 24) & 0xFF);
        result[1] = (byte) ((value >>> 16) & 0xFF);
        result[2] = (byte) ((value >>> 8) & 0xFF);
        result[3] = (byte) (value & 0xFF);
        return result;
    }
}

Related

  1. longToCharArray(long seat, int length)
  2. longToCharBounds(long value)
  3. longToCompare(Long value)
  4. longToDB(long val)
  5. longToEightBytes(final long value)
  6. longToFrontInt(long data)
  7. longToLex(long v)
  8. longToLittleEndianBytes(long value, byte[] destination, int offset, int length)
  9. longToN62(long l)