Here you can find the source of toBinary(int val)
public static String toBinary(int val)
//package com.java2s; //License from project: Open Source License public class Main { public static String toBinary(int val) { StringBuilder builder = new StringBuilder(); builder.append("0x").append(Integer.toHexString(val)).append(" = "); for (int i = 31; i >= 0; i--) { String digit = ((1 << i) & val) == 0 ? "0" : "1"; builder.append(digit).append((i % 4 == 0) ? " " : ""); }/*w w w . j a va2 s . c o m*/ return builder.toString(); } }