Multiply/V2

From Esolang
Jump to navigation Jump to search
Back to Multiply
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

Multiply but with binary conversion.

Python Intepreter

def binaryToDecimal(n):
    return int(n,2)
def decimalToBinary(n):
    return bin(n).replace("0b","")
def intepret(code):
    ac=1
    t="int"
    for c in code:
        if c == 'x':
            if t == "bin":
                ac = binaryToDecimal(ac)
            ac*=-3
            if t == "bin":
                ac = decimalToBinary(ac)
        elif c == 'y':
            if t == "bin":
                ac = binaryToDecimal(ac)
            ac*=-2
            if t == "bin":
                ac = decimalToBinary(ac)
        elif c == 'z':
            if t == "bin":
                ac = binaryToDecimal(ac)
            ac*=-1
            if t == "bin":
                ac = decimalToBinary(ac)
        elif c == "c":
            if t == "int":
                ac = decimalToBinary(ac)
                t="bin"
            elif t == "bin":
                ac = binaryToDecimal(ac)
                t="int"
    if t == "bin":
       if ac[0] == "-":
           ac = "-0b" + ac[1:]
       else:
           ac = "0b" + ac
    input(ac)
intepret(input(">>> "))

See also