I am trying to increment a binary sequence in python while maintaining the bit length. So far I am using this piece of code...
'{0:b}'.format(long('0100', 2) + 1)
This will take the binary number, convert it to a long, adds one, then converts it back to a binary number. Eg, 01 -> 10.
However, if I input a number such as '0100', instead of incrementing it to '0101', my code increments it to '101', so it is disregarding the first '0', and just incrementing '100' to '101'.
Any help on how to make my code maintain the bit length will be greatly appreciated. Thanks