Using JAVA programming language, create a number system conversion application that will do the following: Convert octal to decimal, Convert octal to binary, Convert octal to hexadecimal.
This is the SAMPLE OUTPUT:
NUMBER SYSTEMS APP (HEXADECIMALNUMBER SYSTEMS)
Operations:
Press [1] –Hexadecimalto DecimalConversion
Press [2] –Hexadecimalto BinaryConversion
Press [3] –Hexadecimalto OctalConversion
Select operation: 1
Enter hexadecimal: 1A5
Decimalequivalent is 421
Answers
Answer:
Programiz
Search Programiz
Java Program to Convert Octal Number to Decimal and vice-versa
In this program, you'll learn to convert octal number to a decimal number and vice-versa using functions in Java.
To understand this example, you should have the knowledge of the following Java programming topics:
Java Methods
Java Operators
Java while and do...while Loop
Example 1: Program to Convert Decimal to Octal
public class DecimalOctal {
public static void main(String[] args) {
int decimal = 78;
int octal = convertDecimalToOctal(decimal);
System.out.printf("%d in decimal = %d in octal", decimal, octal);
}
public static int convertDecimalToOctal(int decimal)
{
int octalNumber = 0, i = 1;
while (decimal != 0)
{
octalNumber += (decimal % 8) * i;
decimal /= 8;
i *= 10;
}
return octalNumber;
}
}