Advertisement
Bkmz

Untitled

Sep 30th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3.  
  4. from itertools import izip_longest
  5. import string
  6. from binascii import hexlify
  7.  
  8. # global variables
  9.  
  10. # end global variables
  11.  
  12. def convert():
  13.     pass
  14.  
  15. def unconvert():
  16.     pass
  17.  
  18.  
  19. fd = open("bin", "wb")
  20.  
  21. def grouper(n, iterable, fillvalue=None):
  22.     "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
  23.     args = [iter(iterable)] * n
  24.     return izip_longest(fillvalue=fillvalue, *args)
  25.  
  26. def convert2bin(intStr):
  27.     return '{0:x}'.format( intStr )
  28.  
  29. num = 3405848999
  30.  
  31. print convert2bin(num).zfill(8)
  32.  
  33. for i in grouper(2, convert2bin(num).zfill(8), 0):
  34.     i = string.join(i, "")
  35.     print i
  36.     fd.write(chr(int(i, 16)))
  37.  
  38. fd.close()
  39.  
  40. fd = open("bin", "rb")
  41. read = fd.read()
  42. print read
  43.  
  44. print int(hexlify(read), 16)
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement