Computers like powers of 2, people like powers of 10, and the fact that 2^{10} is approximately 10^{3} makes it easy to convert between the two powers.

A kilobyte is 1000 bytes like a kilogram is 1000 grams. But the former is only approximate and the latter is exact. A kilobyte is actually 2^{10} = 1024 bytes. Similarly a megabyte is 2^{20} or approximately 10^{6} bytes and a gigabyte is 2^{30} or approximately 10^{9} bytes. About 10 years ago the International Electrotechnical Commission (IEC) introduced new units to eliminate this ambiguity. The prefix “kibi” means exactly 2^{10}, “mebi” means 2^{20}, and “gibi” means 2^{30}. (The IEC also introduced tebi, pebi, exbi, zebi, and yobi as binary analogs for tera, peta, exa, zetta, and yota.)

I’ll give arguments for and against using the new units and conclude with a note about their implementation in PowerShell.

**Pro**

The number of bytes in a kilobyte is about 2.5% larger than the number of grams in a kilogram. But the number of bytes in a megabyte is about 5% larger than the number if grams in a megagram. Every time you go up by a factor of 2^{10}, the approximation degrades about another 2.5%. So a terabyte is almost 1.1 trillion bytes. (Why does the quality of the approximation (2^^{10})^{k} ≈ 10^{3k} by about 2.5% for each increment in k? Because by the binomial theorem, (1 + 0.024)^{k} ≈ 1 + 0.024 k.) At larger sizes, the traditional prefixes become progressively more misleading and hence the need for more precise alternatives is greater.

Another advantage to the new prefixes is that “kibi, mebi, gibi” is reminiscent of “*veni*, *vidi*, *vici*.”

**Con**

The only thing special about decimal powers of 2 — 2^{10}, 2^{20}, 2^{30} etc. — is that they are approximately round numbers in base 10 that have traditional prefixes associated with them. From a computer hardware perspective, numbers like 2^{16}, 2^{32}, and 2^{64} are more natural. If you’re not going to use the traditional prefixes, abandon them rather than create near copies. Just state the number of bytes, using scientific notation if necessary.

**PowerShell**

In Windows PowerShell, the units kb, mb, and gb to mean 2^{10}, 2^{20}, and 2^{30}. For example, if you type `2mb + 5gb`

at the PowerShell command prompt, the result is 2102272. If you really want to compute 2×10^{6} + 5×10^{3} and can’t do it in your head, you could type `2e6 + 5e3`

.

Bruce Payette commented on this feature of PowerShell in his book PowerShell in Action.

Yes, the PowerShell team is aware that these notations are not consistent with the IEC recommendations (kibabyte, and so on). Since the point of this notation is convenience and most people in the IT space are more comfortable with Kb than with Ki, we choose to err on the side of comfort over conformance in this one case. Sorry. This particular issue generated easily the second most heated debate on the PowerShell internal and external beta tester lists.

Read More