This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Explanation needed for this program  RSS feed

 
Arvind Kurmi
Greenhorn
Posts: 13
Firefox Browser Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why every times 16 is display? can any one explain me this?
 
Adam Johansson
Greenhorn
Posts: 3
Eclipse IDE Linux Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect Java decides you want to see the result in decimal.

Check out http://www.java-forums.org/java-lang/7211-how-convert-integer-hexadecimal-octal-number.html

EDIT:

If you're unsure what octal, decimal and hexadecimal means, check out:

http://mathworld.wolfram.com/Octal.html
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any numeric literal that starts with a "0" is considered to be written in Octal - or base 8. That means you can only use the digits from 0-7, and each position represents powers of 8.

Literals that begin with "0x" are considered Hexadecimal, which means you can use the digits 0-9 plus A-F. Each position represents a power of 16.

This sounds weird, but makes perfect sense for computers and representing things stored in computers.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arvind Kurmi wrote:Why every times 16 is display? can any one explain me this?

Did you expect something else? For example, did you expect that it would display "0x10" when you initialize the integer with 0x10?

Note that decimal, octal and hexadecimal are just different ways to represent numbers. But the number itself it just a number and nothing more: it does not have some property that says that the number is decimal, octal or hexadecimal. In other words, the variable doesn't know anything about how you wrote it in your source code.
 
Arvind Kurmi
Greenhorn
Posts: 13
Firefox Browser Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Johansson, fred rosenberger , Jesper de Jong.
thanks
it was really helpful
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!