Binary Number

class Binary:
def __init__(self, bin):
self.bin = bin

def checkBin(self):
self.bin = str(self.bin)
for i in range(0, len(self.bin)):
if int(self.bin[i]) != 0 and int(self.bin[i]) != 1:
return "Invalid Binary Format,Not A Binary Number."

else:
return f"Your Binary Number Is - {self.bin}"

def onesComplement(self):
binary_number = bin1.checkBin()
checkBinResult = f"Your Binary Number Is - {self.bin}"
if binary_number == checkBinResult:
self.bin = str(self.bin)
self.bin = list(self.bin)
for i in range(0, len(self.bin)):
if self.bin[i] == '0':
self.bin[i] = '1'
elif self.bin[i] == '1':
self.bin[i] = '0'

self.bin = "".join(self.bin)
return f"1's Complement Of Your Binary Number Is - {self.bin}"

else:
return "1's Complement Of Your Number Is Not Possible."


bin1 = Binary(10100011)
print(bin1.checkBin())
print(bin1.onesComplement())

Comments

Popular posts from this blog

Python Program To Store Marks

Currency.txt

Python Comprehensions