NumPy – bitwise or

NumPy - bitwise or

In this chapter, we will discuss about NumPy bitwise or. The bitwise OR operation on the corresponding bits of binary representations of integers in input arrays is computed by the np.bitwise_or() function.

Example Of NumPy bitwise or

import numpy as np 
a,b = 13,17 
print 'Binary equivalents of 13 and 17:' 
print bin(a), bin(b)  

print 'Bitwise OR of 13 and 17:' 
print np.bitwise_or(13, 17)

Its output is as follows −

Binary equivalents of 13 and 17:
0b1101 0b10001

Bitwise OR of 13 and 17:
29

You can verify this output using the following table. Consider the following Bitwise OR truth table.

ABOR
111
101
011
000
1101
AND
10001
result11101

The decimal equivalent of 11101 is 29.

Next Topic – Click Here

This Post Has 34 Comments

Leave a Reply