diff --git a/Program to convert binary number to decimal b/Program to convert binary number to decimal new file mode 100644 index 0000000..5acc1ee --- /dev/null +++ b/Program to convert binary number to decimal @@ -0,0 +1,22 @@ +public class BinaryDecimal { + + public static void main(String[] args) { + long num = 110110111; + int decimal = convertBinaryToDecimal(num); + System.out.printf("%d in binary = %d in decimal", num, decimal); + } + + public static int convertBinaryToDecimal(long num) + { + int decimalNumber = 0, i = 0; + long remainder; + while (num != 0) + { + remainder = num % 10; + num /= 10; + decimalNumber += remainder * Math.pow(2, i); + ++i; + } + return decimalNumber; + } +}