public class Main5 {
public static void main(String[] args) {
//输出cafebabe,因为后一个加数是int型,是一种混合类型的计算(mixed-type computation),
//Java进行了拓宽原生类型转换(widening primitive conversion),由于0xcafebabe的高位是1,该数是负数,扩展之后变成了0xffffcafebabe,
//因此进行的运算是
// 0xffffffffcafebabeL
//+0x0000000100000000L
//=0x00000000cafebabeL
System.out.println(Long.toHexString(0x100000000L + 0xcafebabe));
//将0xcafebabe标记为long即可
System.out.println(Long.toHexString(0x100000000L + 0xcafebabeL));
//教训:避免混合类型的计算
}
}
转载于:https://my.oschina.net/magicly007/blog/91819