Advertisement
here2share

# b_binary_incr.py

Dec 27th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. # b_binary_incr.py
  2.  
  3. cache = {}
  4. def b_binary_incr(b, incr=1):
  5.     if b in cache:
  6.         return cache[b]
  7.    
  8.     value = int(b, 2)
  9.     value = (value + incr) % (2 ** len(b))
  10.     result = f"{value:0{len(b)}b}"
  11.    
  12.     cache[b] = result
  13.     return result
  14.  
  15. xy = end = '0' * 16
  16. while 1:
  17.     print(xy)
  18.     xy = b_binary_incr(xy)
  19.     if xy == end:
  20.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement