class byteshift
{
public static void main(String args[])
{
byte b;
double d=417;
b=(byte)d;
System.out.print(b);
}
}
// ANSWER SHOULD BE 417-256=161 BUT I AM GETTING -95 WHAT IS HAPPENING HERE.
Printable View
class byteshift
{
public static void main(String args[])
{
byte b;
double d=417;
b=(byte)d;
System.out.print(b);
}
}
// ANSWER SHOULD BE 417-256=161 BUT I AM GETTING -95 WHAT IS HAPPENING HERE.
A byte holds a signed value that can have a max positive value of 127 (0x7F). If the high order (the sign) bit is set, the value is negative.
Print out the values using the Integer class's toHexString() method to see what bits are set.