var a = 1 << 31; //a = -2147483648 var b = a >>> 0; //b = 2147483648 var c = b << 0; //c = -2147483648
知道了>>>操作符之后,这个leetcode问题就很好解决了,顺便把我的答案附上
1 2 3 4 5 6 7 8 9 10 11 12 13
var reverseBits = function(n) { var m = 0; var index = 31; while(n) { var tmp = n & 1; if(tmp) { m = m | (tmp << index); } index -= 1; n = n >>> 1; //注意,使用无符号右移 } return m>>>0; //m默认是有符号数,强制转换成无符号数 };
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public static native int hello(int num);