Beispiel #1
0
def numberToExcess(number):
    number = DB.baseToDecimal(number, __BIN_BASE__)
    number = list(number)
    number = [str(int(i) + 3) for i in number]
    number = "".join(number)

    # Retorno como BCD
    number = numberToBcd(DB.decimalToBase(number, __BIN_BASE__))
    return number
Beispiel #2
0
def excessToNumber(number, base):
    # number is BIN bcd
    number = bcdBinToNumber(number)
    number = [str(int(i) - 3) for i in number]
    number = "".join(number)
    number = DB.decimalToBase(number, base)

    # Retorna en base del numero original del BCD ( o sea pre-añadido el exceso )
    return number
Beispiel #3
0
def bcdToNumber(number, base):
    # Remember that checkbase returns true when there's an error
    # number es bin BCD

    while len(number) % 4 != 0:
        number = '0' + number
    number = bcdBinToNumber(number)
    number = DB.decimalToBase(number, base)
    return number
Beispiel #4
0
def numberToBcd(number):
    # number en BIN
    number = DB.baseToDecimal(number, __BIN_BASE__)
    number = list(number)
    number = [DB.decimalToBase(i, __BIN_BASE__) for i in number]

    # This block of code gives us the binary BCD
    for i in range(len(number)):
        while len(number[i]) < 4:
            number[i] = '0' + number[i]
    number = "".join(number)
    number = str(int(number))
    return number
Beispiel #5
0
def hammmingToNumber(number, base):
    #number is BIN
    c = 0
    power = 2**c
    number = list(number)
    while power < len(number):
        number[power - 1] = ""
        c += 1
        power = 2**c
    number = "".join(number)
    number = DB.baseToDecimal(number, __BIN_BASE__)
    number = DB.decimalToBase(number, base)
    return number
Beispiel #6
0
def grayToNumber(number, base):
    # number == BIN posicion
    number = list(number)
    for i in range(1, len(number)):
        if int(number[i]) + int(number[i - 1]) == 1:
            number[i] = "1"
        else:
            number[i] = "0"
    number = "".join(number)
    # number esta en BIN aqui
    number = DB.baseToDecimal(number, __BIN_BASE__)
    number = DB.decimalToBase(number, base)
    return number
Beispiel #7
0
def johnsonToNumber(number, base):
    # number en BIN

    numberList = list(number)
    ceroCount = 0

    for value in numberList:
        if value == "0":
            ceroCount += 1

    if numberList[__START_POS__] == "1":
        number = len(numberList) + ceroCount
    else:
        number = len(numberList) - ceroCount
    number = DB.decimalToBase(number, base)
    return number
Beispiel #8
0
def numberToHamming(number):
    error = -1
    while error != 0:
        number = list(number)
        maxLenBin = len(DB.decimalToBase(len(number), __BIN_BASE__))
        number = list(enumerate(number))
        number = [[decimalToBinWithCeros(i + 1, maxLenBin), j]
                  for i, j in number]
        redundantC = redundantCuantity(number)
        pos = maxLenBin - 1
        error = list()
        for i in range(redundantC):
            bit = ""
            c = 0
            for i, j in number:
                if i[pos] == "1":
                    if j == "1":
                        c += 1
            bit = c * "1"
            if (int(numberToParity(bit))):
                error.append("0")
            else:
                error.append("1")
            pos -= 1

        error.reverse()
        error = "".join(error)
        error = DB.baseToDecimal(error, __BIN_BASE__)
        error = int(error)
        errorValue = number[error - 1][1]
        if error > 0:
            if (int(errorValue)):
                number[error - 1][1] = '0'
            else:
                number[error - 1][1] = '1'
        number = [j for i, j in number]
        number = "".join(number)
    return number
Beispiel #9
0
def decimalToBinWithCeros(number, maxLen):
    number = DB.decimalToBase(number, __BIN_BASE__)
    while len(number) < maxLen:
        number = '0' + number
    return number
Beispiel #10
0
def pentabitToNumber(number, base):
    # number en BIN
    number = DB.baseToDecimal(number, __BIN_BASE__)
    number = DB.decimalToBase(number, base)
    return number