• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Primitive(Octal,Hexadecimal)

 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. // int j = 08; // Compile time error
Because octal number can't be 8.
2. int i= 0x10;

Question:
When the first is producing compile-time error then why second is not producing a compile-time error.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because in octal 1 and 0 both exists.........some of the people might be taking as '10' but it's basically 1 and 0 and thus will not give any compile error.
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by garima_cs:
because in octal 1 and 0 both exists



Actually, 0x10 is hex.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Octal is a base-8 number system.
The 8 digits used to create an octal representation are {0,1,2,3,4,5,6,7}.
Clearly, 8 is not permitted in an octal representation, hence, compile-time error.

Hexadecimal is a base-16 number system.
The 8 digits used to create a hexadecimal representation are {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}.
Clearly, both 1 and 0 are permitted in a hexadecimal representation, hence, no compile-time error.

Decimal is a base-10 number system.
The 10 digits used to create a decimal representation are {0,1,2,3,4,5,6,7,8,9}.

Binary is a base-2 number system.
The 2 digits used to create a binary representation are {0,1}.

...
 
reply
    Bookmark Topic Watch Topic
  • New Topic