Number System in Java Programming Language
Table of contents
Number System in Java
There are four types of number systems in java programming Language.
Binary Number System
Octal Number System
Decimal Number System
Hexadecimal Number System
Binary Number System :
- In this number system, we use “0b”(2 as base) as prefix to convert the binary into integer format.
class Demo{
public static void main(String[] args){
int a=0b1010;
System.out.println(a);
}
}
- Output for above example is 10.
Octal Number System :
- In this number system, we use “0”(8 as base)as prefix to convert the octal format into integer format.
class Demo{
public static void main(String[] args){
int a=033;
System.out.println(a);
}
}
- Output for above example is 27.(not 33)
Decimal Number System :
In this number system, it is a normal decimal values(10 as base)which we call as integers.
Example is given below.
class Demo{
public static void main(String[] args){
int a=123;
System.out.println(a);
}
}
- Output is 123
Hexa-Decimal Number System :
In this Number system, we use “0x”(16 as base)as prefix to convert the hexadecimal format into integer.
In the below code we can see the example.
class Demo{
public static void main(String[] args){
int a=0xAB;
System.out.println(a);
}
}
- Output for the above program is 171.(A=10, B=11=> 16A+1B==171).
Subscribe to my newsletter
Read articles from Hemanth Raju directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Hemanth Raju
Hemanth Raju
I am a Software Engineer by profession. Loves to write articles on tech concepts and also contribute to open-source