Java Utililty Methods Binary to Decimal

List of utility methods to do Binary to Decimal

Description

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

Method

intbin2dec(String bin)
bindec
int dec = 0, n = 1;
for (int i = bin.length() - 1; i >= 0; i--) {
    dec += n * ('1' == bin.charAt(i) ? 1 : 0);
    n <<= 1;
return dec;
intbin2dec(String str)
bindec
int num = Integer.parseInt(str, 2);
return num;
inttoDecimal(String binary)
This will convert the given binary string to a decimal based integer
long num = Long.parseLong(binary);
long rem;
while (num > 0) {
    rem = num % 10;
    num = num / 10;
    if (rem != 0 && rem != 1) {
        System.out.println("This is not a binary number.");
        System.out.println("Please try once again.");
...