Number System in Java Programming Language

Number System in Java Programming Language

Table of contents

No heading

No headings in the article.

Number System in Java

There are four types of number systems in java programming Language.

  1. Binary Number System

  2. Octal Number System

  3. Decimal Number System

  4. 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).