Java Integer to intToFourByte(long value, byte[] dest, int off)

Here you can find the source of intToFourByte(long value, byte[] dest, int off)

Description

int To Four Byte

License

Open Source License

Declaration

public static void intToFourByte(long value, byte[] dest, int off) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String ERR_VALUE_OOB = "Value out of bounds (%s)";
    public static final long MAX_32BITS = 4294967295L;

    public static byte[] intToFourByte(long value) {
        byte[] buf = new byte[4];
        intToFourByte(value, buf, 0);/*w w  w  .ja  va  2  s. co  m*/
        return buf;
    }

    public static void intToFourByte(long value, byte[] dest, int off) {
        if ((value < 0) || (value > MAX_32BITS))
            throw new IllegalArgumentException(String.format(ERR_VALUE_OOB, value));

        dest[off + 0] = (byte) ((value & 0xFF000000L) >> 24);
        dest[off + 1] = (byte) ((value & 0x00FF0000L) >> 16);
        dest[off + 2] = (byte) ((value & 0x0000FF00L) >> 8);
        dest[off + 3] = (byte) ((value & 0x000000FFL));
    }
}

Related

  1. intToEle(int integEle)
  2. intToEncodedID(int input)
  3. IntToEnode62(Integer int10)
  4. IntToEnode62(Integer int10)
  5. intToFixedLengthString(int value, int length)
  6. intToFourBytes(int i)
  7. intToFourBytes(int iValue, byte b[], int offset)
  8. intToFourChars(int value)
  9. intToGoodBadSimple(int i)