. given an integer, add its binary number by 1 without using "+"
private static int addOne(int num) {
// 10111
int t = 1;
while ((num & t) != 0) {
num &= (-1 ^ t);
t <<= 1;
}
return num | t;
}
没有评论:
发表评论