ankit maini wrote:...
How to solve these types of problems ?
How to identify the sign?
In
Java, the integral primitives (byte, short, int, and long) are stored as
signed two's complements. See
Cornell - Two's Complement.
In your example, the int 3249 is represented as 32-bits, 0000 0000 0000 0000 0000 0000 1011 0001.
When you narrow this to an 8-bit byte, it becomes 1011 0001.
In two's complement, the most significant bit (the one farthest to the left) is the "sign bit." If that's a 1, then the value is negative. So the byte 1011 0001 is negative. As explained by the link above, the absolute value of this negative number is determined by inverting the bits and adding one.
Inverting 1011 0001 results in 0100 1110, and adding 1 results in 0100 1111, which is 79 in decimal. So it's -79.