Open dillonlee06 opened 1 year ago
2.1 done by April 7
def convertToBinary(n):
# b represents the binary number
b = ""
# n represents the decimal number that will be converted into the binary number
while n > 0:
# r represents the remainder
r = n % 2
b = str(r) + b
n = n // 2
return b.zfill(8)
n = int(input("What decimal number would you like to convert to binary?"))
print("User input: ", n)
b = convertToBinary(n)
print("The number {} in binary is {}".format(n,b))
def convertToDecimal(b):
# n represents the decimal number
n = 0
# p represents the position (power) of the binary digit (2 raised to the 0, to the 1st, to the 2nd, etc.)
p = 0
# goes through the binary digits from right to left
for digit in reversed(b):
if digit == '1':
n += 2 ** p
p += 1
return n
b = input("What binary number would you like to convert to decimal? ")
print("User input: ", b)
n = convertToDecimal(b)
print("The number {} in decimal is {}".format(b, n))
Binary Math
Truth Tables
Logic Gates
https://github.com/nVarap/blog/issues/21
^ Review ticket
Varalu, Harsha, Emaad, Ryan