Java Integer to intToOneByteArray(int number)

Here you can find the source of intToOneByteArray(int number)

Description

Returns the int as a byte array with just one entry.

License

Open Source License

Parameter

Parameter Description
number int of the converted number

Return

byte array of size one with the int as a byte

Declaration

public static byte[] intToOneByteArray(int number) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  w w  . ja  va2s  . c o  m*/
     * Returns the int as a byte array with just one entry.
     *
     * @param number int of the converted number
     * @return byte array of size one with the int as a byte
     */
    public static byte[] intToOneByteArray(int number) {
        return new byte[] { intToByte(number) };
    }

    /**
     * Converts a int to a byte.
     *
     * @param number int number
     * @return byte of the int
     */
    public static byte intToByte(int number) {
        if (number <= 255 && number > 0)
            return (byte) number;
        else
            return Byte.MIN_VALUE;
    }
}

Related

  1. intToNumericFormat(int src)
  2. intToOctal(int value)
  3. IntToOctString(final int value)
  4. intToOneByte(int i)
  5. intToOneByte(int value)
  6. IntToPackage(int pack)
  7. intToPaddedString(int value, int pad)
  8. intToPercent(int value)
  9. intToPlusMin(int i)