为什么第一种方式正常工作(给我值2 ^ 32):
long negationMask = 0;
for (long i = 0 ; i < 31 ; i ++)
negationMask |= 1 << i;
Log.i("DBG", " Negation mask: " + Long.toBinaryString(negationMask));
negationMask <<= 1;
Log.i("DBG", " Negation mask: " + Long.toBinaryString(negationMask));
negationMask |= 1;
Log.i("DBG", " Negation mask: " + Long.toBinaryString(negationMask));
而第二个没有(给我2 ^ 64的值):
long negationMask = 0;
for (long i = 0 ; i < 32 ; i ++)
negationMask |= 1 << i;
Log.i("DBG", " Negation mask: " + Long.toBinaryString(negationMask));
问题可能与编译器完成的优化有关吗?我使用的是Android Studio 1.5(Win7)