Java Utililty Methods Decimal to Binary

List of utility methods to do Decimal to Binary

Description

The list of methods to do Decimal to Binary are organized into topic(s).

Method

Stringdec2bin(int dec)
decbin
if (0 == dec)
    return "0";
StringBuffer sb = new StringBuffer();
while (dec != 0) {
    sb.append(1 == dec % 2 ? 1 : 0);
    dec >>= 1;
return sb.reverse().toString();
...
Stringdec2bin(Integer str)
decbin
String num = Integer.toBinaryString(str);
return num;
StringdecimalToBinaryString(int n)
decimal To Binary String
return Integer.toBinaryString(n);
StringdecimalToBitString(int n, int min, int max)
decimal To Bit String
max -= min;
n -= min;
if (max == 0 || n < 0 || n > max) {
    return "";
int biggestPower = (int) logBaseN(max + 1, 2);
int maxInBiggestPower = (int) Math.pow(2, biggestPower);
if (n < maxInBiggestPower) {
...