Skip to content

Instantly share code, notes, and snippets.

@Mic92
Last active July 28, 2021 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/2e7c31fbce1e08bdf5d34b2eec83ae3f to your computer and use it in GitHub Desktop.
Save Mic92/2e7c31fbce1e08bdf5d34b2eec83ae3f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import pdb
import os
from tempfile import TemporaryDirectory
def format_bytes(size):
# 2**10 = 1024
power = 2 ** 10
n = 0
unit = {0: "", 1: "KB", 2: "MB", 3: "GB", 4: "TB", 5: "PT"}
while size > power:
size /= power
n += 1
return f"{size:0.1f} {unit[n]}"
def inspect_num(n: int):
print(f"hex {hex(n)}")
print(f"bin {bin(n)}")
print(f"dec {n}")
print(f"oct {oct(n)}")
print(f"unit {format_bytes(n)}")
def i(n: int):
return inspect_num(n)
with TemporaryDirectory() as d:
os.chdir(d)
with open(".pdbrc", "w") as f:
f.write("alias i inspect_num(%1)\n")
breakpoint()
"bincalc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment