//不允许创建临时变量,交换两个数的内容
#include<stdio.h>
int main()
{
int a = 10;//1010
int b = 20;//10100
//整型:32比特位
//按位异或:相同为0,相异为1
//0和a异或产生a
//00000000 00000000 00000000 00001010
//00000000 00000000 00000000 00010100
//00000000 00000000 00000000 00011110---现在的a
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d \n", a, b);
return 0;
}
//求十个整数中的最大值
#include<stdio.h>
int main()
{
int arr[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 0 };
int max = arr[0];
int i = 0;
for (i = i; i <= 10; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
}
printf("max = %d\n", max);
return 0;
}
//求一个函数返回参数二进制中1的个数*****
//计算的是补码
#include<stdio.h>
int main()
{
int count = 0;
int num = -1;
while (num)
{
count++;
num = num & (num - 1);
}
printf("%d\n", count);
}