Here you can find the source of toLong(String string)
public static long toLong(String string)
//package com.java2s; //License from project: Open Source License public class Main { public static long toLong(String string) { if (!isBinary(string)) return 0; if (string.length() > 63) return Long.MAX_VALUE; return Long.parseLong(string, 2); }//from w w w.j a va2s . com public static boolean isBinary(String binary) { if (binary == null || binary.length() == 0) return false; for (char c : binary.toCharArray()) if (!(c == '0' || c == '1')) return false; return true; } }