Number.fromBytesTo
fromBytesTo($unit) -> number
Description
Convert a number of bytes to another byte unit. (e.g. Kilobytes)
There are two sets of unit prefixes to make it clear as to whether a number of bytes is expressed as Decimal (Base 10) or Binary (Base 2).
For more information, see Ubuntu Units Policy and Binary Prefixes.
$bytes = 1200000 $bytes.fromBytesTo('MB') //= 1.2
Decimal (Base 10)
These are the recommended default units, especially for numbers that will be displayed to end users.
This is used by non-Windows operating systems when displaying disk and file sizes.
Unit (SI) | Name | Size |
---|---|---|
B |
Bytes | — |
kB |
Kilobytes | (103) 1,000 Bytes Note the small “k”! |
MB |
Megabytes | (106) 1,000,000 bytes |
GB |
Gigabytes | (109) 1,000,000,000 bytes |
TB |
Terabytes | (1012) 1,000,000,000,000 bytes |
Binary (Base 2)
Mainly used for displaying RAM sizes.
Unit (IEC) | Name | Size |
---|---|---|
KiB |
Kibibytes | (210) 1,024 bytes |
MiB |
Mebibytes | (220) 1,048,576 bytes |
GiB |
Gibibytes | (230) 1,073,741,824 bytes |
TiB |
Tebibytes | (240) 1,000,000,000,000 bytes |
Bytes vs BitsThere are 8 bits in a byte. Bit units are mainly used to express network speeds and are expressed with small “b” or “bit”. (e.g. “Mb” = Megabit = 1,000,000 bits)