Java Long to longTo4LengthBytes(long num)

Here you can find the source of longTo4LengthBytes(long num)

Description

long To Length Bytes

License

Open Source License

Declaration

public static byte[] longTo4LengthBytes(long num) 

Method Source Code

//package com.java2s;
/*/* w w  w  . j  a  v a 2s .  com*/
 * @(#)ByteConvertUtil.java   V0.0.1 2015-2-3, ????1:37:07
 *
 * Copyright 2015 www.ifood517.com. All rights reserved.
 * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {

    public static byte[] longTo4LengthBytes(long num) {
        int i = (int) (num);
        return intToBytes(i);
    }

    public static byte[] longTo4LengthBytes(long num, byte[] data, int index) {
        int i = (int) (num);
        return intToBytes(i, data, index);
    }

    public static byte[] intToBytes(int i) {
        byte[] intBytes = new byte[4];
        intBytes[0] = (byte) (i >> 24);
        intBytes[1] = (byte) (i >> 16);
        intBytes[2] = (byte) (i >> 8);
        intBytes[3] = (byte) (i >> 0);
        return intBytes;
    }

    public static byte[] intToBytes(int i, byte[] data, int index) {
        data[index] = (byte) (i >> 24);
        data[index + 1] = (byte) (i >> 16);
        data[index + 2] = (byte) (i >> 8);
        data[index + 3] = (byte) (i >> 0);
        return data;
    }
}

Related

  1. long2longArr(long val, long[] res)
  2. long2MacAddress(long l)
  3. long2minLeb(final long x)
  4. longTo36Str(String str)
  5. longTo4ByteArray(byte[] bytes, int offset, long value)
  6. LongToAscii(long number, byte[] buf, int offset, int length)
  7. longToBaseCode(char[] target, int targetOffset, long value, int base, int lengthLimit, boolean fillZeros, boolean upperCase)
  8. longToBasicType(long l, Class clazz)
  9. longToBcd(long num, int size)