Skip to content

Instantly share code, notes, and snippets.

@scentoni
Created October 14, 2021 17:38
Show Gist options
  • Save scentoni/c9cec7cff3698f0381261062272147bb to your computer and use it in GitHub Desktop.
Save scentoni/c9cec7cff3698f0381261062272147bb to your computer and use it in GitHub Desktop.
ibitize: take an integer argument, return a string using ibi binary prefixes
#!/usr/bin/python
# ibitize: take an integer argument, return a string using ibi binary prefixes
# echo '32*2^30'|bc
# 34359738368
# echo 'l(34359738368)/l(2)' |bc -l
# 35.00000000000000000036
# ibitize 34359738368
# 32.0 Gi
import sys
from math import log
def ibitize(x):
b = int(log(x,1024))
return (x/(1024**b),['','Ki','Mi','Gi','Ti','Pi','Ei','Zi','Yi'][b])
x = float(sys.argv[1])
print('{0[0]} {0[1]}'.format(ibitize(x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment