I want to define a function umklappen
that takes in the dual representation of a number base 10 as a list and flip the bit 1->0 and 0->1. I ran into the problem that the type ntobasetwo(n,c)
is of the class NoneType
. I'm not sure why this is the case and how to get around this in my case.
# Funktion, die ganze Zahlen im Dezimalsystem als Zahlen im Dualsystem darstellt
import numpy as np
import math
# Decimal number is converted into binary by dividing the number successively by 2
# and printing the remainder in reverse order
def ntobasetwo(n,c):
binary = []
while n!= 0:
bit = n%2
binary.insert(0, bit)
n = n//2
if len(binary)>c:
binary = binary[0:c]
print(binary)
bin_1248 = ntobasetwo(1248,5)
def umklappen(binList):
for i in range(len(binList)):
if binList[i] == 0:
binList[i] = 1
else:
binList[i] = 0
print(binList)
umklappen_bin_1248 = umklappen(bin_1248)
umklappen_bin_1248