This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integer to Byte Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integer to Byte" Watch "Integer to Byte" New topic

Integer to Byte

Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 182


how the convertion from integer to byte happens?
byte y=(byte)230;

y value is the result will be -26
anyone please help me.....
Ankit Garg

Joined: Aug 03, 2008
Posts: 9400

Well Banu the value 230 is out of the range of byte which is from -128 to 127. So the value 230 will be truncated. This truncation happens at the binary level. Just read a tutorial about Number Systems to understand this concept...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Don't get me started about those stupid light bulbs.
subject: Integer to Byte
It's not a secret anymore!