Converts a digital storage quantity between bit, byte, decimal (KB/MB/GB/TB) and binary (KiB/MiB/GiB/TiB) units per IEC 80000-13.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
value (number, from_unit, required) min 0 : The data size to convert
from_unit (string, required) one of: bit, byte, KB, MB, GB, TB, KiB, MiB, GiB, TiB : Unit of the input value
to_unit (string, required) one of: bit, byte, KB, MB, GB, TB, KiB, MiB, GiB, TiB : Unit to convert into
Outputs
result (to_unit): The converted data size
Steps
Look up the exact bit-equivalent of from_unit and of to_unit: byte=8 bits; KB/MB/GB/TB are 8*1000^n bits (decimal); KiB/MiB/GiB/TiB are 8*1024^n bits (binary).
Convert the input to bits: bits = value * bits_per(from_unit).
Convert bits to the target unit: result = bits / bits_per(to_unit).
Round result to 6 significant figures.
Constants
bit = 1 bit (source: IEC 80000-13:2008)
byte = 8 bit (source: IEC 80000-13:2008)
KB = 8000 bit (source: IEC 80000-13:2008)
MB = 8000000 bit (source: IEC 80000-13:2008)
GB = 8000000000 bit (source: IEC 80000-13:2008)
TB = 8000000000000 bit (source: IEC 80000-13:2008)
KiB = 8192 bit (source: IEC 80000-13:2008)
MiB = 8388608 bit (source: IEC 80000-13:2008)
GiB = 8589934592 bit (source: IEC 80000-13:2008)
TiB = 8796093022208 bit (source: IEC 80000-13:2008)
Sources
IEC 80000-13:2008 (International Electrotechnical Commission, 2026-09-30T19:29:48Z) - Defines the binary prefixes kibi (2^10), mebi (2^20), gibi (2^30), tebi (2^40), distinct from the SI decimal prefixes kilo/mega/giga/tera (powers of 1000) used for KB/MB/GB/TB.