Java Integer to intToTwoByte(int value, byte[] destination, int offset)

Here you can find the source of intToTwoByte(int value, byte[] destination, int offset)

Description

int To Two Byte

License

Open Source License

Declaration

public static void intToTwoByte(int value, byte[] destination, int offset) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String ERR_VALUE_OOB = "Value out of bounds (%s)";
    public static final int MAX_16BITS = 65535;

    public static byte[] intToTwoByte(int value) {
        if ((value < 0) || (value > MAX_16BITS))
            throw new IllegalArgumentException(String.format(ERR_VALUE_OOB, value));

        byte[] buf = new byte[2];
        intToTwoByte(value, buf, 0);/*from   w  ww .  ja va2 s  .  co  m*/
        return buf;
    }

    public static void intToTwoByte(int value, byte[] destination, int offset) {
        if ((value < 0) || (value > MAX_16BITS))
            throw new IllegalArgumentException(String.format(ERR_VALUE_OOB, value));
        destination[offset] = (byte) ((value & 0x0000FF00L) >> 8);
        destination[offset + 1] = (byte) ((value & 0x000000FFL));
    }
}

Related

  1. intToStringBuffer(final int param, final int len)
  2. intToStringWithZeroFill(int intValue, int width)
  3. intToTime(int time)
  4. intToTime(int value)
  5. intToTriplePlace(int i)
  6. intToTwoBytes(int value)
  7. intToTwoDigitString(int integer)
  8. intToTwoHexString(final int value)
  9. intToUByte(int i)