Java Utililty Methods Integer to

List of utility methods to do Integer to

Description

The list of methods to do Integer to are organized into topic(s).

Method

byte[]intTo2LengthBytes(int i)
int To Length Bytes
short s = (short) i;
return shortToBytes(s);
byte[]intTo2UnsignedBytes(int val)
This method receives an signed int and converts it to the equivalent unsigned byte values of the two least significant bytes of the int.
int upperBound = (int) Math.round(Math.pow(2, 16) - 1);
int lowerBound = 0;
if (val < lowerBound || val > upperBound) {
    throw new IllegalArgumentException("Argument has to be 0 <= val <= (2^16-1)");
int no256s = val / 256;
byte[] out = new byte[2];
out[0] = (byte) no256s;
...
StringintTo8HexString(int i)
Create a string with an hexadecimal representation of an integer.
String str = Integer.toHexString(i).toUpperCase();
while (str.length() < 8) {
    str = "0" + str;
return str;
StringintToAlgebraicLoc(int loc)
Converts an integer location in [0, 64) to a string in "algebraic notation" (ie.
if (loc == -1)
    return "-";
int out = loc % 8;
int up = loc / 8;
char outc = (char) (out + 'a');
char upc = (char) (up + '1');
return outc + "" + upc;
StringintToAlpha(Integer no)
convert int from 0 - ..
if (no > 25) {
    return intToAlpha(no - 26);
return String.valueOf((char) (65 + no));
intintToASN1(byte[] d, int idx, int val)
Output an length or integer value in ASN.1 Does NOT output the tag e.g.
if (val < 0 || val > 65535)
    throw new IllegalArgumentException("fixme length " + val);
if (val > 127) {
    if (val > 255) {
        d[idx++] = (byte) 0x82;
        d[idx++] = (byte) (val >> 8);
    } else {
        d[idx++] = (byte) 0x81;
...
StringintToBase32(int n)
int To Base
char[] buffer = new char[7];
for (int i = 6; i >= 0; i--) {
    int x = n & 0x1f;
    buffer[i] = BASE32_CHARS[x];
    n = n >> 5;
    if (n == 0) {
        return new String(buffer, i, 7 - i);
return new String(buffer);
TintToBasicType(int i, Class clazz)
int To Basic Type
if (clazz.equals(Boolean.class))
    return (T) Boolean.valueOf(intToBoolean(i));
if (clazz.equals(Byte.class))
    return (T) intToByte(i);
if (clazz.equals(Character.class))
    return (T) intToCharacter(i);
if (clazz.equals(Short.class))
    return (T) intToShort(i);
...
byte[]intToBcd(int src, int len, int flag)
int To Bcd
return longToBcd(src, len, flag);
voidintToBigEndian(int value, byte[] array, int index)
int To Big Endian
array[index] = (byte) (value >> 24);
array[index + 1] = (byte) (value >> 16);
array[index + 2] = (byte) (value >> 8);
array[index + 3] = (byte) (value);