Advertisement
here2share

# increment_binary_string.py

Dec 21st, 2021
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. # increment_binary_string.py
  2.  
  3. def increment_binary(s):
  4.    return '{:04b}'.format(1 + int(s, 2))
  5.  
  6. x = '0000'
  7. for _ in xrange(16):
  8.    print x
  9.    x = increment_binary(x)
  10.    
  11. '0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement