Java Program to Illustrate the usage of Octal Integer
Octal is a number system where a number is represented in powers of 8. So all the integers can be represented as an octal number. Also, all the digit in an octal number is between 0 and 7. In java, we can store octal numbers by just adding 0 while initializing. They are called Octal Literals. The data type used for storing is int.
The method used to convert Decimal to Octal is Integer.toOctalString(int num)
public static String toOctalString(int num)
Parameters: The method accepts a single parameter num of integer type which is required to be converted to a string.
Return Value: The function returns a string representation of the integer argument as an unsigned integer in base 8.
Value of a: 20 Value of a: 20 Value of c: 20 Octal Representation of the number 50 is: 62
Example 2: The different arithmetic operation can also be performed on this octal integer. Operation is the same as performed on the int data type.
Value of a: 100 Value of b: 20 Addition: 120 Subtraction: 80 Multiplication: 2000 Division: 5