File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes while converting int to byte? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while converting int to byte?" Watch "while converting int to byte?" New topic

while converting int to byte?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
i am trying to convert int to byte.
in binary : 0000 0000 0000 0000 0000 0001 0010 1100
after truncating HO bytes 0010 1100
inverting 1101 0011
adding one 1101 0100

manually doing i am getting this as output. but the complier is showing 44 .may i know why ? am i wrong in any step ?please help


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11927

you only need to invert/add 1 if the lead/high bit is 1. Since after the truncation the lead bit is 0, you shouldn't.

Then it's simply adding up the powers of 2 to get 44.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
thank you very much .
I agree. Here's the link:
subject: while converting int to byte?
It's not a secret anymore!