This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Downcasting and the value

 
nishant vats
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code
char s1 = (char)78890;
int i1 = s1;
System.out.println(i1);

output
13354


while downcasting there is modulo divison..
am nt able to get the above value
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The casting logic is very simple. For Char the maximum value that you can put is 65536. So if u cast 78890 to assign to Char it will go to 0 (LIKE CYCLIC after completing one cycle of 65536) and assign
13354 since 78890-65536=13354.

Similarly if u assign char c=(char)-100, it is equivalent to 65536-100=65436. This is the casting logic that takes place for 'char'. For int,byte, etc...also it is the same except that after completing a cycle it will go to the -Ve minimum.

Clear???
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a hint:
System.out.println(Character.MAX_VALUE + 13354);
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic