BinPython

From Esolang
Jump to navigation Jump to search

BinPython

The name tells it all.. Binary-Python

A language which is indeed a brother of python, but in BINARY!

There is one Windows executable to run Binpython files.. Which can be found in its Github Repo

The main program file is in fact written in BinPython ITSELF!

The long-form source code is 334kb in size


Let's Teach you some BinPythoning..

There are some basic rules:

  1. There are only 2 characters.. (0 and 1)
  2. All characters other than 0 and 1 are ignored
  3. All codes are Python codes but, in binary (ASCII)


Sample program:


Hello, world:

01110000011100100110100101101110011101000010100000100010010010000110010101101100011011000110111100101100001000000101011101101111011100100110110001100100001000010010001000101001

Output:

Hello, World!!

Conversion

BinPython to Python

def binPythonToPython(s):
	s = "".join(c for c in s if c in "01")
	if len(s) & 7:
		raise SyntaxError("Wrong length")
	unbin = lambda s: int(s, 2)
	z = lambda s: tuple(map("".join, zip(*(s[i::8] for i in range(8)))))
	return "".join(tuple(map(lambda x: chr(unbin(x)), z(s))))

Python to BinPython

def pythonToBinPython(s):
	return "".join(map(lambda c: bin(ord(c))[2:].rjust(8, "0"), s))