File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Logical Operators
2
+ # p = True
3
+ # print('not p value is : ', not p)
4
+
5
+ # Lesson18
6
+ # Bitwise Operators
7
+ # Bitwise operators are used to compare (binary) numbers:
8
+
9
+ # Bitwise AND
10
+ a = 60
11
+ b = 13
12
+ c = 0
13
+ c = a & b
14
+ # print('bitwise and operation', c)
15
+
16
+ # 60 /2 & 13/2 , 2|60 - 0 2|13 -1
17
+ # 2|30 - 0 2|6 - 0
18
+ # 2|15 - 1 2|3 -1
19
+ # 2|7 - 1 2|1
20
+ # 2|3 - 1
21
+ # 2|1
22
+ # 1 1 1 1 0 0 # 1 1 0 1
23
+ # 0 0 1 1 0 1
24
+ # Ans Bitwise & 0 0 0 0 1 1 0 0 = 12
25
+
26
+
27
+ # Bitwise OR
28
+ e = 60
29
+ f = 13
30
+ g = 0
31
+ g = e | f
32
+ # print('bitwise or operation', g)
33
+
34
+ # 111100
35
+ # 001101
36
+ # Ans Bitwise | 00111101 = 61
37
+
38
+
39
+ # Bitwise Nor
40
+ a = ~ 10
41
+ # print('Bitwise Nor', a)
42
+ # format => - (num + 1 )
43
+
44
+ # decimal to binary 2|10 - 0
45
+ # 2|5 - 1
46
+ # 2|2 -0
47
+ # 2|1
48
+ # 1010 (need to add 1)
49
+ # -(1011)
50
+
51
+ # Two's complement
52
+ # 10 => 1010
53
+ # inverse => 0101
54
+ # plus one => 0110
55
+ # and then change plus to minus , minus to plus
56
+
57
+
58
+
59
+
60
+
61
+
You can’t perform that action at this time.
0 commit comments