Transcript for:
Java Program for Number System Conversion

Hello, this tutorial is to discuss about a Java program to convert a decimal number into a binary pattern and vice versa. That means a binary number back into a decimal number. The logic for the program is written inside a main Java class which is named as decimal binary in the main method. A scanner object has been created to read. a decimal and binary number from the user so the scanner object name is sc which requires the java.util package to be imported into the program by using system.out.print we display the message that enter the decimal number. Decimal number can be accepted that means an integer number can be accepted by calling the method nextInt of scanner class by using its object sc and the decimal number we have stored in the variable d. the decimal number which we have accepted will first get converted into its binary equivalent the binary equivalent of a decimal number can be found by using integer wrapper class and its corresponding method to binary string two binary string method can be used to convert an integer into a binary form and it returns a binary form in the format of string representation. So any integer number can get converted into a binary pattern by using two binary string method of an integer wrapper class. And the data will be displayed by using system.out.print method. The binary pattern which we are getting by using integer.toBinaryString method. It is not stored in a variable. It is directly displayed by using system.out.print method. Similarly, we will accept a binary number. A binary pattern will be accepted from the user by using the scanner class method next. which will accept a binary string in the format of string the binary pattern which we have accepted in the form of string can be converted into its corresponding decimal number by using the integer wrapper class method parseInt in the parseInt we can pass two parameters the first one is a string representation of the number a string which consists of a number here the number is in the format of binary pattern. The second parameter is the radix of the number. The radix is the base of the number. So our number is currently in the form of binary. So the radix is 2. So it will convert the binary pattern into its corresponding decimal equivalent integer number. So we can call the method parseInt. Here both two binary string and parseInt method are the static method. That's why we can call directly by using the integer wrapper class. So parseInt method will convert the binary pattern in the form of string which is there in the variable p into its corresponding integer value. Execute and see the program output. Thank you for watching this video.