Skip to content

Instantly share code, notes, and snippets.

@vampjaz
Created January 11, 2016 15:27
Show Gist options
  • Save vampjaz/b7d768692ace5f867173 to your computer and use it in GitHub Desktop.
Save vampjaz/b7d768692ace5f867173 to your computer and use it in GitHub Desktop.
Random cs stuff
def bintohex(b):
b = str(b);bd = [];hv = []
while b:
if len(b) >= 4:
a = b[-4:]
b = b[:-4]
else:
a = '0'*(4-len(b)) + b
b = ''
bd.append(a)
for i in bd:
tmp = 0;mu = 1
for j in reversed(i):
if j=='1':tmp += mu
mu *= 2
hv.append(tmp)
print ''.join(reversed(['0123456789ABCDEF'[i] for i in hv]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment