Java Long Number Create toLong(String string)

Here you can find the source of toLong(String string)

Description

to Long

License

Open Source License

Declaration


public static long toLong(String string) 

Method Source Code

//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;
    }
}

Related

  1. toLong(String str)
  2. toLong(String str)
  3. toLong(String str)
  4. toLong(String str, long defaultValue)
  5. toLong(String str, long val)
  6. toLong(String string)
  7. toLong(String string)
  8. toLong(String string)
  9. toLong(String strVal)