Pages

Friday 12 July 2013

HOW TO REPRESENT NUMBER SYSTEMS IN PROGRAMMING LANGUAGE???

In this real world we have 4 types of number systems they are:
1.binary number system           [format:0,1]
2.octal number system             [format:0,1----7]
3.decimal number system        [format:0,1-----9]
4.hexa decimal system             [format:0,1---9,a,b,c,d,e,f ] 
genarally we use the decimal number system in any programming language.

  In java we can represent the binary values by giving ob infront of the number
ex: int ob10;(correct)
     int x=o4235;(wrong)

representation of the binary number feature is introduced in java 1.7


we can represent the octal values in java programming language by giving o infront of the number
ex: int i=o24;(correct)
        int k=o248;(wrong)[because octal range 0-7]

we can represent the hexa decimal values in java programming language by giving ox infront of the number
ex: int i=ox123;(correct)
        int k=ox245a;(wrong)
         int k=123a;(wrong)

note:JVM takes the binary data ,octal data,decimal data,hexa decimal data convert in the form of decimal format and give the output as adecimal
example programme:
  class ndemo
{
public static void main(String args[])
{
  int i=24;
int j=o72;
int k=ox2a;
int l=ob10;
System.out.println(i);
System.out.println(j);
System.out.println(k);
System.out.println(l);
}
}
note:this programme run java 1.7 or above versions because binary values format does not suppport java 1.7 below versions.
output:
24
58
42
2


0 comments:

Post a Comment