@Test public void binValueOf() { assertEquals(BitStrings.binValueOf("00000000000000000000000000000000011111111111111111111"), 1048575); assertEquals(BitStrings.binValueOf("00000000000000000000000000000000000011100000000000000"), 114688); }
public static long binValueOf(final String binaryStr) { if (Strings.isEmpty(binaryStr)) { return 0; } long value = 0; long height = 1; for (int i = binaryStr.length() - 1; i >= 0; i--) { if ('1' == binaryStr.charAt(i)) { value += height; } height *= 2; } return value; }
BitStrings { public static long binValueOf(final String binaryStr) { if (Strings.isEmpty(binaryStr)) { return 0; } long value = 0; long height = 1; for (int i = binaryStr.length() - 1; i >= 0; i--) { if ('1' == binaryStr.charAt(i)) { value += height; } height *= 2; } return value; } }
BitStrings { public static long binValueOf(final String binaryStr) { if (Strings.isEmpty(binaryStr)) { return 0; } long value = 0; long height = 1; for (int i = binaryStr.length() - 1; i >= 0; i--) { if ('1' == binaryStr.charAt(i)) { value += height; } height *= 2; } return value; } BitStrings(); }
BitStrings { public static long binValueOf(final String binaryStr) { if (Strings.isEmpty(binaryStr)) { return 0; } long value = 0; long height = 1; for (int i = binaryStr.length() - 1; i >= 0; i--) { if ('1' == binaryStr.charAt(i)) { value += height; } height *= 2; } return value; } BitStrings(); static String and(final String first, final String second); static String or(final String first, final String second); static String andWith(final String str, final String boolString); static String convertToBoolStr(final String first); static long binValueOf(final String binaryStr); static String reverse(final String binaryStr); }
BitStrings { public static long binValueOf(final String binaryStr) { if (Strings.isEmpty(binaryStr)) { return 0; } long value = 0; long height = 1; for (int i = binaryStr.length() - 1; i >= 0; i--) { if ('1' == binaryStr.charAt(i)) { value += height; } height *= 2; } return value; } BitStrings(); static String and(final String first, final String second); static String or(final String first, final String second); static String andWith(final String str, final String boolString); static String convertToBoolStr(final String first); static long binValueOf(final String binaryStr); static String reverse(final String binaryStr);  }