Here you can find the source of toBin(int bin, int size)
public static String toBin(int bin, int size)
//package com.java2s; //License from project: Open Source License public class Main { public static String toBin(int bin, int size) { String ret = Integer.toBinaryString(bin); return normalizeNumber(ret, size); }/*from w w w . j a v a 2 s .c o m*/ private static String normalizeNumber(String ret, int size) { int addCount = size - ret.length(); if (addCount > 0) { for (int i = 0; i < addCount; i++) { ret = "0" + ret; } } else { ret = ret.substring(ret.length() - size, ret.length()); } return ret; } }