Java Binary to Decimal bin2dec(String bin)

Here you can find the source of bin2dec(String bin)

Description

bindec

License

Open Source License

Declaration

private static int bin2dec(String bin) 

Method Source Code

//package com.java2s;
/*/*from   w ww.j a va2 s .  c  o m*/
 * (C) Copyright IBM Corp. 2008
 *
 * LICENSE: Eclipse Public License v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    private static int bin2dec(String bin) {
        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;
    }
}

Related

  1. bin2dec(String str)
  2. toDecimal(String binary)