1

I just realized that in PowerShell (or even the Windows environment in general), this is how units of size are regarded:

1mb ... 1048576 ......... not 1000000
1gb ... 1073741824 ...... not 1000000000
1tb ... 1099511627776 ... not 1000000000000

Can somebody please explain this madness to me? Why in the world is 1mb considered 1048576 and not 1000000?

phuclv
  • 26,555
  • 15
  • 113
  • 235
oldboy
  • 345
  • 2
  • 5
  • 15

2 Answers2

6

First I must note that there are BIG differences between b and B with the latter (byte) being 8 times as big as the former (bit). And the prefix is also case-sensitive. There are no g or t, whereas m means "milli" which can't apply to unit sizes like bit or byte. A value like 1 mb = 1 millibit doesn't make sense

Regarding the prefixes, it has almost always been in binary for decades in computer-related fields, because electronic computers operate in binary. If one says they have 1 GB of RAM, it means they have 1024 MB of memory and not 1000 MB, as sizes of memory chips are always powers of 2. Same to many other units like hard disk block sizes where 4K means 4096 and not 4000. Here are some examples of prefixes

  • 1 K = 210 = 1024 ≈ 103
  • 1 M = 220 = 210 K = 1024 × 1024 ≈ 106
  • 1 G = 230 = 210 M = 220 K = 1024 × 1024 × 1024 ≈ 109

For a rough conversion just multiply/divide by powers of 10 like in the normal SI way. The result will be close enough if the 2 units aren't too far from each other.

A new class of separate prefixes for binary values were proposed in 1995 but didn't get traction until almost 10 years ago when Linux and Mac began switching to using the prefixes in their decimal values

The transition made disk sizes suddenly "change" after an OS update (because the old MB is larger than the new MB), leaving many confused users. Linux command-line tools still use the binary prefix (probably except a few new tools for manipulating disk partitions which need to show decimal or binary depending on the situation). RAM sizes are still reported in binary because of the reason I mentioned above.

Windows didn't adopt the new convention and still uses the prefixes exclusively with their binary values

The details of Ubuntu's policy is like this

There are two ways to represent big numbers: You could either display them in multiples of 1000 = 103 (base 10) or 1024 = 210 (base 2). If you divide by 1000, you probably use the SI prefix names, if you divide by 1024, you probably use the IEC prefix names. The problem starts with dividing by 1024. Many applications use the SI prefix names for it and some use the IEC prefix names. The current situation is a mess. If you see SI prefix names you do not know whether the number is divided by 1000 or 1024. There is already a Brainstorm idea for it: Fix file size confusion.

Policy

  • Applications must use IEC standard for base-2 units:
  • 1 KiB = 1,024 bytes (Note: big k)
  • 1 MiB = 1,024 KiB = 1,048,576 bytes
  • 1 GiB = 1,024 MiB = 1,048,576 KiB = 1,073,741,824 bytes
  • 1 TiB = 1,024 GiB = 1,048,576 MiB = 1,073,741,824 KiB = 1,099,511,627,776 bytes
  • Applications must use SI standard for base-10 units:
  • 1 kB = 1,000 bytes (Note: small k)
  • 1 MB = 1,000 kB = 1,000,000 bytes
  • 1 GB = 1,000 MB = 1,000,000 kB = 1,000,000,000 bytes
  • 1 TB = 1,000 GB = 1,000,000 MB = 1,000,000,000 kB = 1,000,000,000,000 bytes

...

Exception

The application can keep their previous behavior for backwards compatibility if the following points apply. The application may add an option to display the sizes in base-10, too.

  • is a command-line tool
  • is often parsed by machine (for example, the output is used in scripts)
  • only the prefix is displayed and not the unit (for example, M instead of MB)

Some applications which fall under this rule are:

  • df
  • du
  • ls

https://wiki.ubuntu.com/UnitsPolicy

phuclv
  • 26,555
  • 15
  • 113
  • 235
3

It's just a matter of which base you are working with. In base 10 (how humans work) 1 MB is 1 Million Bytes

  • 1 Megabyte is equal to 1000000 bytes (decimal).
  • 1 MB = 106 B in base 10 (SI).

In Base 2 (Binary), the numbers are not so round.

  • 1 Megabyte is equal to 1048576 bytes (binary).
  • 1 MB = 220 B in base 2.
phuclv
  • 26,555
  • 15
  • 113
  • 235
ziptron
  • 183
  • 1
  • 6
  • is linux also the same way as windows ?? any suggestion on how to handle the conversions for somebody who hasnt done math in a long while? – oldboy Jan 01 '20 at 05:21
  • @oldboy for Linux command line apps, yes. Conversions can be quickly done like in decimal in most situations – phuclv Jan 01 '20 at 09:03