Codecademy Python Answers Introduction To Bitwise Operators

Contents

Also Read :   Codecademy Python Answers Introduction to Classes

 Also Read: How To Chat With Your Friend Using Command Prompt

Introduction to Bitwise Operators 1/14 – Just a Little Bit

print 5 >> 4  # Right Shift
print 5 << 1  # Left Shift
print 8 & 5   # Bitwise AND
print 9 | 4   # Bitwise OR
print 12 ^ 42 # Bitwise XOR
print ~88     # Bitwise NOT

Introduction to Bitwise Operators 2/14 – Lesson 10: The Base 2 Number System

print b1,    #1
print b10,   #2
print b11,   #3
print b100,  #4
print b101,  #5
print b110,  #6
print b111   #7
print "******"
print b1 + b11
print b11 * b11

Introduction to Bitwise Operators 3/14 – I can Count to 1100

one = b1
two = b10
three = b11
four = b100
five = b101
six = b110
seven = b111
eight =b1000
nine = b1001
ten = b1010
eleven = b1011
twelve = b1100

Introduction to Bitwise Operators 4/14 – The bin() Function

print bin(1)
print bin(prathap)
for i in range(2,6):
    print bin(i)

Introduction to Bitwise Operators 5/14 – int()’s Second Parameter

Also Read :   Codecademy Python Answers Python Syntax
print int("1",2)
print int("10",2)
print int("111",2)
print int("0b100",2)
print int(bin(5),2)
# Print out the decimal equivalent of the binary 11001001.
print 201

Introduction to Bitwise Operators 6/14 – Slide to left! Slide to right

shift_right = b1100
shift_left = b1

# Your code here!


print bin(shift_right)
print bin(shift_left)

shift_right = shift_right>>2
shift_left = shift_left<<2

print bin(shift_right)
print bin(shift_left)

Introduction to Bitwise Operators 7/14 – A Bit of this AND that

print bin(b1110 & b101)

Introduction to Bitwise Operators 8/14 – A Bit of this OR that

print bin(b1110 | b101)

Introduction to Bitwise Operators 9/14 – This XOR that

print bin(b1110 ^ b0101)

Introduction to Bitwise Operators 10/14 – See This is not that hard

print ~1
print ~2
print ~3
print ~42
print ~123

Introduction to Bitwise Operators 11/14 – The Man behind the bit mask

def check_bit4(input):
    ptp = b1000
    desired = ptp & input
    if desired>:
        return "on"
    else:
        return "off"
        
    

Introduction to Bitwise Operators 12/14 – Turn it on

a = b10111011
b = b10111111
desired = bin(a | b)
print desired

Introduction to Bitwise Operators 13/14 – Just Flip out

a = b11101110
b = b11111111
desired = bin(a ^ b)
print desired

Introduction to Bitwise Operators 14/14 – Slip and Slide

def flip_bit(number,n):
    mask=(b1<<n-1)
    return bin(number^mask)

Leave a Reply

Your email address will not be published. Required fields are marked *