Bitwise operators in Python

Bitwise operators are available in python.

#!/usr/bin/python3

def binaries(n):
    print('{:08b}'.format(n))

binaries(2)
# 00000010
# 8 bits = 1 byte, 00000010 = 2
x = binaries(1)
y = binaries(2)
z = binaries(3)

print(id(x))
print(id(y))
print(id(z))

#################
# 138716908
# 138716908
# 138716908
#################
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s