binary.py 518 B

12345678910111213141516171819202122232425
  1. #
  2. # This file is part of pyasn1 software.
  3. #
  4. # Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
  5. # License: http://pyasn1.sf.net/license.html
  6. #
  7. from sys import version_info
  8. if version_info[0:2] < (2, 6):
  9. def bin(value):
  10. bitstring = []
  11. while value:
  12. if value & 1 == 1:
  13. bitstring.append('1')
  14. else:
  15. bitstring.append('0')
  16. value >>= 1
  17. bitstring.reverse()
  18. return '0b' + ''.join(bitstring)
  19. else:
  20. bin = bin