Java Short Number Create toShort(String value)

Here you can find the source of toShort(String value)

Description

to Short

License

Open Source License

Declaration


public static short toShort(String value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static short toShort(String value) {
        if (!isBinary(value))
            return 0;

        if (value.length() > 7)
            return 127;

        return (short) Integer.parseInt(value, 2);
    }//  w ww.jav a 2  s.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. toShort(String numeric)
  2. toShort(String str)
  3. toShort(String str)
  4. toShort(String str, int maxLen)
  5. toShort(String str, short defaultValue)
  6. toShort(String value)
  7. toShort(String value)
  8. toShort(String value, short defaultValue)
  9. toShort(String[] arr)