Utility library to convert and format SI and IEC bit and byte units.
// Ints return an optional, because we only support values >= 0.
// In case you can guarantee this, it’s safe to force unwrap the return value
let value = UInt(4)
let x = BitUnit.convert(value, from: .Megabit, to: .Kilobit)
print(x)
=> 4000
let x = BitUnit.format(1_177_171)!
print(x)
=> "1.2 Mb"
let x = BitUnit.format(UInt64.max, targetUnitType: .BinaryByteUnit)
print(x)
=> "2048 PiB"