In: Computer Science
In Python, write a function one_bit_NOT that takes one argument, a character that is either '0' or '1'. It should perform the NOT operation and return a string with a single character as the result. I.e., if the character argument is "0", it returns a "1"'. If the character argument is "1", it returns a "0".
Source Code:
def one_bit_NOT(ch):
temp=int(ch) # converting char to int i.e, here we get
integer
temp=not(temp) # applying NOT operation i.e, here we get boolean
value
temp=int(temp) # converting boolean to int i.e, here we get
integer
temp=str(temp) # converting int to char i.e, here we get
charcter
return temp # returning character
ch='0'
print(one_bit_NOT(ch)) # it prints '1'
ch='1'
print(one_bit_NOT(ch)) # it prints '0'