Java Integer to Binary intToBinString(int val, int width)

Here you can find the source of intToBinString(int val, int width)

Description

int To Bin String

License

Open Source License

Declaration

public static String intToBinString(int val, int width) 

Method Source Code

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

public class Main {
    static String mZeroes = "00000000000000000000000000000000";

    public static String intToBinString(int val, int width) {
        String str = Integer.toBinaryString(val);
        if (str.length() >= width) {
            return str;
        }//from   w  w  w  .  j a  va  2  s.  com
        return mZeroes.substring(0, width - str.length()) + str;
    }
}

Related

  1. integerToBinString(final int aValue, final int aFieldWidth)
  2. intToBinary(int binary, int digits)
  3. intToBinary(int i)
  4. intToBinary(int i, int byteLength)
  5. intToBinary(long value, int bits)
  6. itob(int i, int j)
  7. ItoB(int x)
  8. iToB(int[] intVals)
  9. itob(long integer, int[] arr)