Here you can find the source of toBin(int size, String bitString)
Parameter | Description |
---|---|
size | a parameter |
bitString | a parameter |
private static String toBin(int size, String bitString)
//package com.java2s; //License from project: Open Source License public class Main { /**//from www .ja v a2 s . c om * Returns the binary representation of an integer. * * @param i - the integer to format as a binary String. * @return the binary representation of the given integer. */ public static String toBin(int i) { return toBin(32, Integer.toBinaryString(i)); } /** * Returns the binary representation of a byte. * * @param b - the byte to format as a binary String. * @return the binary representation of the given byte. */ public static String toBin(byte b) { return toBin(8, Integer.toBinaryString(b & 0xff)); } /** * * * @param size * @param bitString * @return */ private static String toBin(int size, String bitString) { return String.format(String.format("%%%ds", size), bitString).replace(' ', '0'); } }