code: public static long string2long(String s, int radix)
          throws NumberFormatException {
          if (radix == 10) {
              return Long.parseLong(s, radix);
          } else {
              char[] cs = s.toCharArray();
              long limit = Long.MAX_VALUE / (radix/2);
              long n = 0;
              for (int i = 0; i < cs.length; i++) {
                  int d = Character.digit(cs[i], radix);
                  if (n < 0 ||
                      n > limit ||
                      n * radix > Long.MAX_VALUE - d)
                      throw new NumberFormatException();
                  n = n * radix + d;
              }
              return n;
          }
      }
docs: Convert string to long integer.