• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion byte->int

 
Thomas Markl
Ranch Hand
Posts: 192
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is byte 017 different from byte 17?

C:\Java\EigeneJavaProgramme>java Question02b
17
10001
15
1111
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This a bit of java that crept over from C.
Any integral literal that begins with 0 (zero) is taken to be in base 8. So 017 (octal) is 1*8+7 or 15 (decimal). Should have been left behind if you ask me.
You might get a shock if you held a telphone number in a int or long. 017702345 ain't going to be what
you get.
-Barry
[ August 31, 2002: Message edited by: Barry Gaunt ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And while we're at it, byte value 0x17 means 17 in hex = 16+7 = 23.
This is also a carryover from C, but much more useful than octal.
[ August 31, 2002: Message edited by: Ron Newman ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you still have yer PDP 11!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic