This week's book giveaway is in the Servlets forum. We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line! See this thread for details.

Originally posted by sushil bhogale: byte = -42; It gets represented in bits as 1010 1010. How it gets represented as int i.e. in 32 bits ?

First of all, "-42" is not represented as "1010 1010". "1010 1010" is the representation of "-86". The representation of "-42" is "1101 0110".

To answer your question, to upcast a byte to an int, just sign extend the byte -- meaning the last bit is extended to the other bits. Hence, "1101 0110" becomes "1111 1111 1111 1111 1111 1111 1101 0110".