Here you can find the source of intToBinary(int binary, int digits)
Parameter | Description |
---|---|
binary | int |
digits | int |
private static String intToBinary(int binary, int digits)
//package com.java2s; //License from project: Apache License public class Main { /**//from ww w. jav a2 s . com * Converts the given integer to a String representing a binary number * with the specified number of digits * For example when using 4 digits the binary 1 is 0001 * @param binary int * @param digits int * @return String */ private static String intToBinary(int binary, int digits) { String temp = Integer.toBinaryString(binary); int foundDigits = temp.length(); String returner = temp; for (int i = foundDigits; i < digits; i++) { returner = "0" + returner; } return returner; } }