Here you can find the source of toBin(int x)
private static StringBuffer toBin(int x)
//package com.java2s; public class Main { private static StringBuffer toBin(int x) { StringBuffer result = new StringBuffer(); result.append(x % 2);//from w w w .j a v a2s. com x /= 2; while (x > 0) { result.append(x % 2); x /= 2; } return result; } }