forked from sylviot/algoritmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitwise.cpp
More file actions
62 lines (50 loc) · 927 Bytes
/
Bitwise.cpp
File metadata and controls
62 lines (50 loc) · 927 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main(){
int N = 31;// Número 31(base 10) = 11111(base 2)
/*
0001 1111 (31 base 2)
<< (move 1 bit)
---------
0011 1110 (62 base 2)
*/
printf("%d\n", N << 1);
/*
0001 1111 (31 base 2)
>> (remove 1 bit)
---------
0000 1111 (15 base 2)
*/
printf("%d\n", N >> 1);
/*
0001 1111 (31 base 2)
& (operador "E" [and])
0000 0001 (1 base 2)
---------
0000 0001 (1 base 2)
*/
printf("%d\n", N & 1);
/*
0001 1111 (31 base 2)
| (operador "OU" [or])
0000 0001 (1 base 2)
---------
0001 1111 (31 base 2)
*/
printf("%d\n", N | 1);
/*
0001 1111 (31 base 2)
^ (operador "OU exclusivo" [xor])
0000 0001 (1 base 2)
---------
0001 1110 (30 base 2)
*/
printf("%d\n", N ^ 1);
/*
~0001 1111 (31 base 2)
---------
-0010 0000 (-32 base 2)
*/
printf("%d\n", ~N);
return 0;
}