Question: Is there anyway that

```
>>> int('0000001',2)
1

```

Could save the leading 0s ?

What I want to do is, with a huge string of bits, in 8 and 8 bits I would convert to int, and then to char, and write it all in a file. 
Later I would want to read the file, get the char, use ord(), get the int, and then the bits that I entered, with the leading 0s.

Answer: 
You can preserve the number of initial zeroes by finding the first index of `1` (as it is a binary string). 

```
>>> s = '0000001'
>>> '{}{}'.format('0'*s.index('1'),int(s,2))
'0000001'
>>> s = '0000011'
>>> '{}{}'.format('0'*s.index('1'),int(s,2))
'000003'

```

As you can see, only the leading zeroes are preserved and not the number of digits. 

Another implementation (only zeroes included)

```
>>> def change(s):
...      try:
...           return '{}{}'.format('0'*s.index('1'),int(s,2))
...      except ValueError:
...           return s
... 
>>> change('000000')
'000000'
>>> change('000001')
'000001'
>>> change('000011')
'00003'

```
I am not sure what is your use case, but the following would pretty much do its job for what you are looking for

**Implementation**

```
def weird_format(n):
    if not int(n, 2): return n
    return "{{:0{}}}".format(len(n) - len(n.lstrip('0')) + 1).format(int(n,2))

```

**Output**

```
>>> weird_format('000001')
'000001'
>>> weird_format('000101')
'0005'
>>> weird_format('11')
'3'
>>> weird_format('0000')
'0000'

```