Skip to content

Instantly share code, notes, and snippets.

@tbielawa tbielawa/bitmath-shell.py
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.