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