Here you can find the source of convertIntToBitsWithPadding(int num)
public static String convertIntToBitsWithPadding(int num)
//package com.java2s; //License from project: Open Source License public class Main { private static int INT_BIT_COUNT = 1 << 5; public static String convertIntToBitsWithPadding(int num) { 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(); }//ww w . j ava 2 s. c o m public static String convertIntToBits(int num) { 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(); } }