Skip to content

Instantly share code, notes, and snippets.

@jb0hn
Created September 9, 2018 18:02
Show Gist options
  • Save jb0hn/e29e4db5edbeecf5502819b5c9b5ebd9 to your computer and use it in GitHub Desktop.
Save jb0hn/e29e4db5edbeecf5502819b5c9b5ebd9 to your computer and use it in GitHub Desktop.
Binary, decimal, hex counter
#!/usr/bin/env python3
# import modules
import sys
import time
# clear terminal
def cls():
print('\n' * 100)
def main():
cls()
for i in range(1000000):
sys.stdout.write("{:020b}".format(i)) # binary
sys.stdout.write(" ")
sys.stdout.write("{:07d}".format(i)) # decimal
sys.stdout.write(" ")
sys.stdout.write("{:07x}\r".format(i)) # hex
sys.stdout.flush() # reset cursor
time.sleep(0.05) # wait 0.05 s between iterations
# exec
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment