Java Utililty Methods Integer to Bit

List of utility methods to do Integer to Bit

Description

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

Method

StringconvertIntToBits(int num)
convert Int To Bits
StringBuilder builder = new StringBuilder();
while (num != 0) {
    if ((num & 0x1) == 1)
        builder.insert(0, '1');
    else
        builder.insert(0, '0');
    num >>>= 1;
return builder.toString();
StringconvertIntToBitsWithPadding(int num)
convert Int To Bits With Padding
StringBuilder builder = new StringBuilder(convertIntToBits(num));
int length = INT_BIT_COUNT - builder.length();
for (int i = 0; i < length; i++)
    builder.insert(0, '0');
return builder.toString();
StringintToBits(int in, int min, int max, int numBits)
Turns an integer into a bitstring (0s and 1s).
in = in - min;
in = Math.min(in, max - min);
String bits = Integer.toBinaryString(in);
while (bits.length() < numBits)
    bits = "0" + bits;
return bits;
int[]intToBits(int n, int size)
int To Bits
int[] bits = new int[size];
for (int i = 0; i < size; i++) {
    bits[i] = (n / (int) Math.pow(2, i)) % 2;
return bits;
byte[]intToBits(int no)
int To Bits
return intToBits(no, 32);
voidintToBits(int pInt, boolean[] pBits)
Gets the bit string represented by an integer.
int vBitIndex = pBits.length - 1;
for (int i = 0; i < pBits.length; i++) {
    pBits[vBitIndex--] = (((pInt >> i) & 1) == 1);