Monday, 27 May 2019

Bitwise OR Operator (|)

Bitwise OR Operator (|)

a=10 b=11

Converting from Decimal to Binary:

1 byte is 8 bits so remaining are filled with 0’s
a=10 à0000 1010

b=11


b=11->0000 1011

So
a=10->0 0 0 0 1010
b=11->0 0 0 0 1011
-----------
a|b=   0 0 0 0 1 0 1 1
----------
Binary to decimal:
0
0
0
0
1
0
1
1
27
26
25
24
23
22
21
20
--
--
32
16
8
4
2
1
0
0
0
0
8
0
2
1

a|b=0+0+0+8+0+2+1=11 (Add only 1's, and ignore 0s)



Truth Table:

a
b
a|b
0
0
0
0
1
1
1
0
1
1
1
1



No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(...