Here you can find the source of printBits(int number, int n)
public static String printBits(int number, int n)
//package com.java2s; public class Main { public static String printBits(int number, int n) { String s = ""; for (int i = 0; i < n; i++) { s += getBit(number, i) ? "1" : "0"; }/*from w w w .ja v a 2s. com*/ return s; } public static boolean getBit(int number, int i) { return (number & (1 << i)) != 0; } }