Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Last active August 29, 2015 13:57
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 tbielawa/9591035 to your computer and use it in GitHub Desktop.
Save tbielawa/9591035 to your computer and use it in GitHub Desktop.
bitmath is Pythonic! https://github.com/tbielawa/bitmath More information: https://blog.lnx.cx/?p=521
>>> from bitmath import *
>>> GiB(42) * 3
GiB(126.0)
>>> Bit(9) + Byte(3)
Bit(33.0)
>>> exbi = EiB(0.6)
>>> mega = MB(700)
>>> exbi / mega
988218432.5201545
>>> exbi - mega
EiB(0.599999999393)
>>> mega + exbi
MB(6.91752903464e+11)
>>> print "Over 9000 Gibibits: %s" % Gib(9001)
Over 9000 Gibibits: 9001.0Gib
>>> thirty_megabytes = MB(30)
>>> thirty_megabytes.bytes
30000000
>>> thirty_mb_as_kb = kB(bytes=30000000)
>>> print thirty_megabytes, thirty_mb_as_kb
30.0MB 30000.0kB
>>> thirty_megabytes == thirty_mb_as_kb
True
>>> TiB(1) < GB(1000)
False
>>> TiB(1) < GB(10000)
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment