In [46]:
# comments : code for ascii to binary
import binascii
In [48]:
# convert ascii to hex
a = binascii.hexlify("1")
b = binascii.hexlify("0")
print a, b
In [49]:
# convert hex to binary
c = binascii.unhexlify("31")
d = binascii.unhexlify(b)
e = binascii.unhexlify(a)
print d, e
In [50]:
# comment ascii to hex
f = binascii.b2a_hex("1")
print f
In [51]:
# comment ascii to hex
f = binascii.b2a_uu("1")
print f
In [52]:
bin(int(binascii.hexlify('1'), 16))
Out[52]:
In [53]:
binascii.hexlify('1')
Out[53]:
In [54]:
# check base conversion
int('10',16)
Out[54]:
In [55]:
int('0', 2)
Out[55]:
In [94]:
# convert binary to hex value
'%X' % int('1111', 2)
Out[94]:
In [95]:
# convert binary to hex value
'%X' % int('110001', 2)
Out[95]:
In [97]:
# convert binary to ascii value
binascii.unhexlify('%X' % int('110001', 2))
Out[97]:
In [92]:
# convert binary to int value
int('1111', 2)
Out[92]:
In [78]:
int('31', 16)
Out[78]:
In [89]:
bin(7)
Out[89]:
In [77]:
binascii.unhexlify('31')
Out[77]:
In [159]:
# convert ascii zero and one values into binary encoding, error during all zero value and some other values also
a = "11111111"
# convert binary to ascii value
binascii.unhexlify('%X' % int(a, 2))
Out[159]:
In [153]:
# convert ascii zero and one values into binary encoding
a = "01111110"
# convert binary to ascii value
b = binascii.unhexlify('%X' % int(a, 2))
In [154]:
f = open("a2b-out.fp", "w")
print f, b
In [155]:
f.write(b)
f.close()
In [ ]:
In [ ]: