昨天在leetcode做题的时候做到了371,原题是这样的: 371. Sum of Two Integers Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 因为之前完全没有在实际练习中使用过位运算,所以刚看到这道题目的时候我的第一反应是 1.用乘除代替加减,但是一想,
// 不用大与小与号,求两数最大值 #include <stdio.h> int max(int a, int b) { int c = a - b; int d = 1 << 31; if ((c&d) == 0) { return a; } else { return b; } } int main() { printf("%d是大数\n", max(0, 2)); printf("%d是大数\n", max(3, 4)); pr