Java Char Array to Long charArrayToLong(char[] bi)

Here you can find the source of charArrayToLong(char[] bi)

Description

char Array To Long

License

Apache License

Declaration

public static long charArrayToLong(char[] bi) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   w  ww  . j a va2s. com
     * 
    * change from char array to long
    * @param bi
    * @return long  
    * @throws
     */
    public static long charArrayToLong(char[] bi) {
        long len = bi.length;
        long sum = 0;
        long tmp, max = len - 1;
        for (int i = 0; i < len; ++i) {
            tmp = bi[i] - '0';
            sum += tmp * Math.pow(2, max--);
        }
        return sum;
    }
}