Number System in Java Programming Language
Published in
1 min readMar 17, 2021
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=> 16*A+1*B==171).