Java Program to Convert Binary String to Decimal Using Wrapper Class
Given a binary string as input, we need to write a program to convert the given binary string into its equivalent decimal number.
Examples: Input : 1111 Output : 15 Input : 1001101 Output : 77 Input : 1101 Output : 13
The idea is to extract each character of a given binary string using charAt() and convert those characters into their corresponding primitive integer type using Character.getNumericValue() and store those converted integers into the primitive integer type array in reverse order. It works with long binary numbers like 20 bits or 30 bits. As shown in the figure below:
Below is the implementation of the above code idea:
Given Binary: 1101 Equivalent Decimal Number: 13
My Personal Notes arrow_drop_up
Please Login to comment...