List of utility methods to do Binary to Decimal
int | bin2dec(String bin) bindec int dec = 0, n = 1; for (int i = bin.length() - 1; i >= 0; i--) { dec += n * ('1' == bin.charAt(i) ? 1 : 0); n <<= 1; return dec; |
int | bin2dec(String str) bindec int num = Integer.parseInt(str, 2); return num; |
int | toDecimal(String binary) This will convert the given binary string to a decimal based integer long num = Long.parseLong(binary); long rem; while (num > 0) { rem = num % 10; num = num / 10; if (rem != 0 && rem != 1) { System.out.println("This is not a binary number."); System.out.println("Please try once again."); ... |