Python Forum
Simple Binary Translator (Using MATH instead of MATCH))
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Binary Translator (Using MATH instead of MATCH))
#1
I decided to write a text to binary translator only using math. This was to test my abilities because I am very new. This can only translate letters and nothing else. I knew how to do binary in my head, so I made a program without using a dictionary to simply match.

def Binary(phrase):
    ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    def Find(letter):
        Count = 0
        for LETTER in ALPHABET:
            Count += 1
            if letter.upper() == LETTER:
                return Count
                break
    result = ""
    for letter in phrase:
        try:
            output = ""
            value = 0
            if letter.upper() in ALPHABET:
                if letter.upper() == letter:
                    value += 1000000
                    spot = Find(letter)
                    if spot >= 16:
                        value += 10000
                        spot -= 16
                    if spot >= 8:
                        value += 1000
                        spot -= 8
                    if spot >= 4:
                        value += 100
                        spot -= 4
                    if spot >= 2:
                        value += 10
                        spot -= 2
                    if spot >= 1:
                        value += 1
                        spot -= 1
                    output += str(value)
                elif letter.lower() == letter:
                    value += 1100000
                    spot = Find(letter)
                    if spot >= 16:
                        value += 10000
                        spot -= 16
                    if spot >= 8:
                        value += 1000
                        spot -= 8
                    if spot >= 4:
                        value += 100
                        spot -= 4
                    if spot >= 2:
                        value += 10
                        spot -= 2
                    if spot >= 1:
                        value += 1
                        spot -= 1
                    output += str(value)
                result += "0" + output + " "
            else:
                result += "00100000 "
        except:
            pass
    return result
Reply


Messages In This Thread
Simple Binary Translator (Using MATH instead of MATCH)) - by DataCorrupt - Jun-09-2020, 01:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The LOL Translator SpeedyZapGaming 7 6,307 Apr-15-2017, 08:54 AM
Last Post: GamingAgent

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020