Last active
July 19, 2016 20:37
-
-
Save eduardoedson/d3e659cf02761c0074f56db5de337a7b to your computer and use it in GitHub Desktop.
ASCII to Binary / Binary to ASCII
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import binascii | |
import os | |
def to_binary(frase): | |
return bin(int(binascii.hexlify(frase), 16)) | |
def to_ascii(frase): | |
return binascii.unhexlify('%x' % int(frase, 2)) | |
# ====================================================================== | |
function = raw_input('[1] - Passar para ASCII\n[2] - Passar para Binário\n') | |
frase = raw_input('\nQual a frase?\n') | |
os.system('clear') | |
if int(function) == 1: | |
print('Frase em Binário: ' + frase) | |
print('Frase em ASCII: ' + to_ascii(frase)) | |
elif int(function) == 2: | |
print('Frase em ASCII: ' + frase) | |
print('Frase em Binário: ' + to_binary(frase)) | |
else: | |
print('Opção inválida') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment