Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

binary.py 698B

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