1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| int max1(int a,int b){
return b & ( (a-b) >> 31) | a & (~(a-b) >> 31);
}
int max2(int x,int y){
return x ^ ((x^y) & -(x < y));
}
int min1(int a,int b){
return a & ((a-b) >> 31) | b & (~(a-b) >> 31);
}
int min2(int x,int y){
return y ^ ((x^y) & -(x < y));
}
bool isSampSign(int x,int y){
return (x^y) >= 0;
}
int getTwo(int n){
// 2^n
return 2 << (n-1);
}
bool isTwo(int n){
return n > 0 ? (n&(n-1)) == 0:false;
}
int quyu(int m,int n){
return m & (n-1);
}
int getAgv1(int n,int m){
return (n+m) >> 1;
}
int getAgv2(int x,int y){
return ((x^y) >> 1) + (x&y);
}
int getBit(int n,int m){ //从低位到高位 取n的第m位
return (n >> (m-1)) & 1;
}
int setBit1(int n,int m){ //从低位到高位 将n的第m位置1
return n | (1 << (m-1));
}
int setBit2(int n,int m){ //从低位到高位 将n的第m位置0
return n & ~(1 << (m-1));
}
int getnum1(int n){
//get n+1
return -~n;
}
int getnum2(int n){
return ~-n;
}
int getnum3(int n){
return ~n + 1;
}
int main(int argc,char *argv[])
{
int num1 = max1(3,5);
int num2 = max2(3,5);
int num3 = min1(3,5);
int num4 = min2(3,5);
cout<<getnum3(3)<<endl;
//cout<<getBit2(4,1)<<endl;
//cout<<getAgv1(3,5)<<” “<<getAgv2(3,5)<<endl;
//cout<<quyu(2,4)<<” “<<quyu(5,3)<<endl;
//cout<<isTwo(4)<<” “<<isTwo(5)<<endl;
//cout<<getTwo(2)<<endl;
//cout<<isSampSign(-1,2)<<endl;;
//cout<<isSampSign(3,5)<<endl;
//cout<<num3<<” “<<num4<<endl;
//cout<<num1<<” “<<num2<<endl;
return 0;
}
|