• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

fundamentals

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,
examine th code,
class demo{
public static void main(String args[]){
int i=012;
System.out.println(i);
}
}
the result gives 10, why so? and how?,give the full details.
thx
swarna
[LIST]
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any integer literal prefixed by 0 is interpreted to be an octal. 012 is 1 x 8^1 + 2 x 8^0 = 8 + 2 = 10.
 
swarna kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx anthony,now i got it.
swarna
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java has three types of integer literals:
- decimal: 123, 345, 3764632, ...
- octal: 012, 0345, 076, 012, ...
- hexadecimal: 0xF4E3, 0XABDC, 0x0254, ...
Note that:
- decimal literals are composed of digits from 0 to 9 where the left-most digit cannot be 0.
- octal literals always begin with a 0 followed by digits ranging from 0 to 7
- hexadecimal literals always begin with 0x (zero lowercase x) or 0X (zero uppercase x) followed by digits ranging from 0 to 9 and letters ranging from A to F (upper- or lowercase letters)
[ July 11, 2002: Message edited by: Valentin Crettaz ]
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to convert Hexadecimal to decimal?
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You convert hexidecimal to decimal the same way you convert octal to decimal:
0132 is (1 x 8^2) + (3 x 8^1) + (2 x 8^0) = 64 + 24 + 2 = 90 (octal)
0x132 is (1 x 16^2) + (3 x 16^1) + (2 x 16^0) = 256 + 48 + 2 = 306 (hexidecimal)
[ July 12, 2002: Message edited by: Jessica Sant ]
 
zarina mohammad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jess ,that was helpful.
 
swarna kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx valentin and jess,
thx for good explanation,
swarna
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic