Here you can find the source of toShort(String value)
public static short toShort(String value)
//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; } }