Java Program to Illustrate the usage of Octal Integer Last Updated : 17 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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) Syntax: 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. Example 1 Java import java.io.*; class GFG { public static void main(String[] args) { // Variable Declaration int a; // storing normal integer value a = 20; System.out.println("Value of a: " + a); // storing octal integer value // just add 0 followed octal representation a = 024; System.out.println("Value of a: " + a); // convert octal representation to integer String s = "024"; int c = Integer.parseInt(s, 8); System.out.println("Value of c: " + c); // get octal representation of a number int b = 50; System.out.println( "Octal Representation of the number " + b + " is: " + Integer.toOctalString(b)); } } OutputValue of a: 20 Value of a: 20 Value of c: 20 Octal Representation of the number 50 is: 62 The time complexity is O(1), meaning it is constant time. The auxiliary space complexity is also O(1). 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. Java // Arithmetic operations on Octal numbers import java.io.*; class GFG { public static void main(String[] args) { int a, b; // 100 a = 0144; // 20 b = 024; System.out.println("Value of a: " + a); System.out.println("Value of b: " + b); System.out.println("Addition: " + (a + b)); System.out.println("Subtraction: " + (a - b)); System.out.println("Multiplication: " + (a * b)); System.out.println("Division: " + (a / b)); } } OutputValue of a: 100 Value of b: 20 Addition: 120 Subtraction: 80 Multiplication: 2000 Division: 5 Comment More infoAdvertise with us Next Article Java Program to Convert Octal to Decimal S sohamk990 Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads Java Program to illustrate the Usage of HexaDecimal A decimal number is the sum of digits multiplied with a power of 10. Decimal numbers are represented with base 10 whereas hexadecimal Number is the sum of digits multiplied with the power of 16, somehow there are similar traits in the internal working of them just they are two different ways to pres 4 min read Java Program to Illustrate Use of Binary Literals A binary literal is a number represented in binary (0s and 1s). In Java, you can use binary literals for integral types such as byte, short, int, and long. To specify a binary literal, prefix the number with 0b or 0B. This allows you to define numbers in binary format directly in your code. When exe 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 Octal to Decimal Octal numbers are numbers with 8 bases and use digits from 0-7. This system is a base 8 number system. The decimal numbers are the numbers with 10 as their base and use digits from 0-9 to represent the decimal number. They also require dots to represent decimal fractions.We have to convert a number 3 min read Java Program For Decimal to Octal Conversion Given a decimal number N, convert N into an equivalent octal number, i.e., convert the number with base value 10 to base value 8. The decimal number system uses 10 digits from 0-9, and the octal number system uses 8 digits from 0-7 to represent any numeric value.Illustration: Basic input/output for 3 min read Like