Java Program to Convert Binary String to Decimal Using Wrapper Class Last Updated : 12 May, 2022 Comments Improve Suggest changes Like Article Like Report 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: Binary String converted to primitive int type array and stored in reverse order Below is the implementation of the above code idea: Java // Program to Convert a given Binary String to // its equivalent decimal number import java.lang.Math; import java.util.Scanner; class BinaryToDecimal { // convertToDec() Method // performs the conversion of // Binary to Decimal static int convertToDec(String bin) { int[] binArray = new int[1024]; int eqv_dec = 0; // Converting characters of Binary String to // primitive integer and storing it in the Array in // reverse order!! for (int i = bin.length() - 1; i >= 0; i--) { binArray[i] = Character.getNumericValue(bin.charAt(i)); } // Evaluating Equivalent Decimal Number from the // Binary Array!! for (int i = 0; i < bin.length(); i++) { if (binArray[i] == 1) { eqv_dec += (int)Math.pow(2, bin.length() - 1 - i); } else continue; } return eqv_dec; } // Driver Code! public static void main(String[] args) { String bin = "1101"; System.out.println("Given Binary: " + bin); int eqv_dec = convertToDec(bin); System.out.println("Equivalent Decimal Number: " + eqv_dec); } } Output: Given Binary: 1101 Equivalent Decimal Number: 13 Comment More infoAdvertise with us Next Article Java Program to Convert Binary String to Decimal Using Wrapper Class anujdas10 Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads Java Program to Convert Binary to Hexadecimal The Hexadecimal number system as the name suggests comprises 16 entities. These 16 entities consist of 10 digits, 0-9 representing the first 10 numbers of the hexadecimal system as well. For the remaining 6 numbers, we use English alphabets ranging from A through F to represent the numbers 10 to 15. 6 min read Java Program to Convert a Decimal Number to Binary Number using Stacks Java is high level, compiled as well as interpreted programming language. Stack is an abstract data type used in most of the programming languages and can be implemented using arrays or linked list. Stack data structure follows the principle of LIFO (Last In First Out) . Stack allows push, pop, peek 3 min read Java Program to Convert a Float value to String Given a Float value in Java, the task is to write a Java program to convert this float value to string type. Examples: Input: 1.0 Output: "1.0" Input: 3.14 Output: "3.14" Strings - Strings in Java are objects that are supported internally by a char array. Since arrays are immutable, and strings are 4 min read Java Program to Convert Byte Array to Hex String Byte Array - A Java Byte Array is an array used to store byte data types only. The default value of each element of the byte array is 0. Hex String - A Hex String is a combination of the digits 0-9 and characters A-F, just like how a binary string comprises only 0's and 1's. Eg: "245FC" is a hexadec 5 min read Java Program to Convert a Decimal Number to Binary Number using Arrays as Stacks Given an Integer number convert into Binary Number using arrays as a stack. Example: Input : 10 Output: 1010 Input : 16 Output: 10000 Approach: Divide the number by 2 and store the remainder of the number in the array.Divide the number by 2.Repeat the process until the number becomes zero.Print the 1 min read Java Program to Convert Double to String The primary goal of double to String conversion in Java is to store big streams of numbers that are coming where even data types fail to store the stream of numbers. It is generically carried out when we want to display the bigger values. In this article, we will learn How to Convert double to Strin 3 min read Java Program to Convert String to Float Value Given a string âstrâ in Java, the task is to convert this string to float type. Methods: This can be done by two methods as listed below: Using parseFloat() Method Using valueOf() Method Let us discuss above two ways of implementing the methods to get a fair understanding of the conversion of string 4 min read Java Program to Convert Binary to Octal A Binary (base 2) number is given, and our task is to convert it into an Octal (base 8) number. There are different ways to convert binary to decimal, which we will discuss in this article.Example of Binary to Octal Conversion:Input : 100100Output: 44Input : 1100001Output : 141A Binary Number System 5 min read Java Program to Convert Octal to Binary Given an Octal number as input, the task is to convert that number into its Binary equivalent number. Example: Input: Octal Number = 513 Output: Binary equivalent value is: 101001011 Explanation : Binary equivalent value of 5: 101 Binary equivalent value of 1: 001 Binary equivalent value of 3: 011Oc 5 min read Java Program to Convert Long to String The long to String conversion in Java generally comes in need when we have to display a long number in a GUI application because everything is displayed in string form. In this article, we will learn about Java Programs to convert long to String. Given a Long number, the task is to convert it into a 4 min read Like