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
letvalue=UInt(4)letx=BitUnit.convert(value, from:.Megabit, to:.Kilobit)print(x)=>4000letx=BitUnit.format(1_177_171)!
print(x)=>"1.2 Mb"letx=BitUnit.format(UInt64.max, targetUnitType:.BinaryByteUnit)print(x)=>"2048 PiB"