# Basic Java – 13 || Decimal values v/s Octal base(8) values in JAVA.

Any numeric value which fulfills below conditions would be treated as octal base(8) values:

1. Should have three or more digits

### Octal base number system

The octal number system is like a binary number system having the base of 8. It works on 0-7 digits values.

Example of Octal numbers, 010, 011, 0111 etc.

As mentioned in the above example, we can see that it is like binary conversion just base gets changed to octal base(8) value. Below are the steps to formalize this process:

1. The integer value is 011
2. Consider the total number of digits is n
3. Consider single digit as d3d2d1 (We can also consider it as di )
4. E is the Exponential value which gets started at 0 and from the left side
5. Value of E would increase by 1 to n-1.
6. 8E x di
7. Summation of the above formula for all the digits will get us an octal value.

Whenever the compiler finds any numeric value starting with 0 and having 3 or more digits, it treats it as an Octal base values.

Try to print int i = 011, the output will be 9 which is the octal value of 011. But here is a trick to print value as it is 011. We could achieve this by using System.out.format() method.

System.out.format(“Display in Octal format: %03o“,temp); (o is O for owl not zero).

System.out.format(“Display in Decimal format: %03d“,temp);

```Related Links:
Basic Java – 1 || Understand Java before start learning JAVA.Basic Java – 2 || Variables and Data Types used in JAVA.Basic Java – 3 || Understanding Class, Objects, Methods in Java.Basic Java – 4 || More on methods(Return Type and Parameters)Basic Java – 5 || Methods- Call by Value and Call by Reference in Java.Basic Java – 6 || Understanding of Constructor and Destructor in JAVA.Basic Java – 7 || Static Variables and Methods.Basic Java – 8 || Lets learn about Arrays in Java.Basic Java – 9 || Performing multiple operations using Java Operators.Basic Java – 10 || Conditions (If and Switch) in JAVA.Basic Java – 11 || for and for-each in Java. (Loops Part-1)Basic Java – 12 || Alternate looping concepts while and do-while. (Loops Part-2)Basic Java – 13 || Decimal values v/s Octal base(8) values in JAVA.Basic Java – 14 || Difference between IndexOf() and lastIndexOf() methods of Strings in JAVA.Basic Java – 15 || Runtime User Input using Scanner Class (Part-1).Basic Java – 16 || Runtime User Input using BufferedReader Class (Part-2).Basic Java – 17 || Runtime User Input using Console Class (Part-3).Basic Java – 18 || Difference between break and continue keywords.Basic Java – 19 || Sending Email using Java (Part-1).Basic Java – 20 || Sending Email with attachment using Java (Part-2).
Java File Handling:
File Handling | Reading data from word document(.doc or .docx) in JAVA.File Handling | Reading data from Excel files (.xls or .xlsx) using JAVA.File Handling | Writing data into an Excel(.XLSX or .XLS) File.File Handling | Implement formatting in Excel using Java.File Handling | Copy existing data from one workbook to another workbook in Java.File Handling | Reading data from PDF file using JAVA.File Handling || Traverse folders and subfolders in Java.File Handling || Reading and Writing data from a text file.File Handling || Multiple file creation using template based input data.Framework || Simple example of Key Driven Framework using excel sheet in Selenium(JAVA).
OOPs Concept:
Java || Abstract class with Constructor.Java | Object Oriented Programming (OOPs) Concept
QnA | Difference between Integer and int keywords.QnA | Can main method be overloaded?QnA | How do I reverse a String/Sentence in Java?QnA | Perform Multiplication and Division without * or / or % operators.QnA | How do I get the default value of data type?QnA | How to split String if it contains period symbol (.) in between?
Java Programs:
Different ways to Reverse a String in Java.Copy formatting & style of cells from one sheet to another.Getting IP address and Hostname using InetAddress Class.User inputs via Command Prompt using arguments of main() method of a class.Program for List and ArrayList in Java.Useful methods and implementation under Scanner Class.Swapping two variable values without using any third variable.Difference between int x= 10 and y=010 in Java.Parameterized Constructors v/s Setter and Getter function in JAVA.Override a Static Method.
```

Code Example:

```/**
* @author ashok.kumar
*
*/
public class Test1 {

/**
* @param args
*/
public static void main(String[] args) {

int l=10;

System.out.println("Numeric:" + l);

int m=010;

System.out.println("Octal value:" + m);

int n=0100;

System.out.println("Octal value:" + n);

int mn=1110;

System.out.println("Numeric:" + mn);

int jk=0112;

System.out.println("Octal value: "+jk);

int temp=0111;

System.out.format("Display in Octal format: %04o",temp);
}
}

Output:
Numeric:10
Octal value:8
Octal value:64
Numeric:1110
Octal value: 74
Display in Octal format: 0111```

More Examples:

Difference between int x= 10 and y=010 in Java. 1129total visits,1visits today