Converting bytes to megabytes
Asked Answered
C

10

153

I've seen three ways of doing conversion from bytes to megabytes:

  1. megabytes=bytes/1000000
  2. megabytes=bytes/1024/1024
  3. megabytes=bytes/1024/1000

Ok, I think #3 is totally wrong but I have seen it. I think #2 is right, but I am looking for some respected authority (like W3C, ISO, NIST, etc) to clarify which megabyte is a true megabyte. Can anyone cite a source that explicitly explains how this calculation is done?

Bonus question: if #2 is a megabyte what are #1 and #3 called?

BTW: Hard drive manufacturers don't count as authorities on this one!

Coulometer answered 2/3, 2010 at 17:11 Comment(11)
Hard drive manufacturers do count as authorities on this one, insofar as their usage of megabyte to mean sense #1 is driving acceptance of that conversion. Note that Microsoft OSs still use sense #2, though.Netsuke
Marketing "engineers" and other folks who can't really compute will divide the number of bytes by a million and call that "MB". Those who know what a MB really is will divide by 2 to the power of 20 (1024 * 1024) and that's the real megabyte.Aspergillum
@marc_s: Marketing engineers that know who sign their paychecks will do whatever arithmetic produces a more impressive number relative to their competitors. Only Plato knows what a "real" megabyte is.Netsuke
#3 should be called a floppy megabyte. 3½ inch floppies were fairly notable for using this (and I don't recall seeing it anywhere else).Glauconite
And the obligatory: xkcd.com/394Astute
Man oh man. Between this and text encoding, I sometimes despair at our unerring ability to add complicating kinks to the most basic things.Lemmons
Leave it to Marketing to screw up what the rest of us would consider "the most basic things"Magulac
I am extremely surprised and concerned at the number of people who think hard drive manufacturers should count as authorities. They definitely have a lot of marketing hype to confuse people but that doesn't make them an authority. It just makes them have a conflict of interest.Coulometer
Hard drive manufacturers most likely use #1 to get the highest number. For GB the difference is 7% and for TB the difference is 10%.Ose
Hard drive manufacturers use #1 because they're engineers. The prefix mega- means 1,000,000 and always has. They've been doing it since before the discrepancy could have made any marketing difference. In fact, the 1024×1024 convention was invented by marketing types because customers didn't understand why 32 + 32 = 65.Caves
The definition depends on if you are counting in binary or decimal: en.wikipedia.org/wiki/Orders_of_magnitude_%28data%29Rafe
T
139

Traditionally by megabyte we mean your second option -- 1 megabyte = 220 bytes. But it is not correct actually because mega means 1 000 000. There is a new standard name for 220 bytes, it is mebibyte (http://en.wikipedia.org/wiki/Mebibyte) and it gathers popularity.

Tarryn answered 2/3, 2010 at 17:13 Comment(8)
What? "We mean 2nd"? That does not make any sort of sense.Fruitful
@Bears: Andrey is referring to #2 in the OP's terms - the 1024^2 bytes version.Dungdungan
I agree with all this, except the implication that it is gathering a lot of popularity. The mindshare of 1024=K and friends is effectively invulnerable. When you get people to start saying "cracker" instead of "hacker", get back to me.Vocal
Not going to downvote for the heretical "mebibyte" mention, but it's taking a lot of effort.Quadrireme
@T.E.D.: actually, the use of "hacker" to mean "cracker" is a perfect example of popular culture overriding the usage that geeks would prefer.Netsuke
it was my personal feeling that mebibyte is gathering popularity, may be i am wrong. i saw on some rather popular download site size shown in MiB and KiB.Tarryn
Well, I agree with you and I also use 10-base mega and 2-base kibi and mebi. That is the IEC standard for metric use: that is final and there is no use kicking over it.Delia
12 years on, general people haven't even heard of this, and most developers still use megabyte when referring to binary mebi. Because, reinventing the wheel is blasphemy, and inherently only meant to convolute something. We already had it's type (binary vs decimal, and that was fine). This is a great example why I got out of the tech field beyond personal gratification. Nothing be shenanigans. Just my opinion.Luxate
C
35

There's an IEC standard that distinguishes the terms, e.g. Mebibyte = 1024^2 bytes but Megabyte = 1000^2 (in order to be compatible to SI units like kilograms where k/M/... means 1000/1000000). Actually most people in the IT area will prefer Megabyte = 1024^2 and hard disk manufacturers will prefer Megabyte = 1000^2 (because hard disk sizes will sound bigger than they are).

As a matter of fact, most people are confused by the IEC standard (multiplier 1000) and the traditional meaning (multiplier 1024). In general you shouldn't make assumptions on what people mean. For example, 128 kBit/s for MP3s usually means 128000 bits because the multiplier 1000 is mostly used with the unit bits. But often people then call 2048 kBit/s equal to 2 MBit/s - confusing eh?

So as a general rule, don't trust bit/byte units at all ;)

Chinchin answered 2/3, 2010 at 17:19 Comment(0)
H
26

Divide by 2 to the power of 20, (1024*1024) bytes = 1 megabyte

1024*1024 = 1,048,576   
2^20 = 1,048,576
1,048,576/1,048,576 = 1  

It is the same thing.

Hypothalamus answered 20/6, 2014 at 11:13 Comment(1)
It is the same thing as what? Itself? Please clarify.Taradiddle
N
21

BTW: Hard drive manufacturers don't count as authorities on this one!

Oh, yes they do (and the definition they assume from the S.I. is the correct one). On a related issue, see this post on CodingHorror.

Nall answered 2/3, 2010 at 21:46 Comment(8)
Sorry downvoter, but their definition of Mega IS the correct one, no matter what programmers think. I can live with M = 2^20, fine, but that is just for historical reasons.Nall
+1 for the moxie of standing with the HD companies and SI standards enthusists against everyone else!Misrule
Thanks Jeffrey :), but it's not just the HD companies: Your CPU does 2600 MHz; Your math processor does XY Mflops; Ethernet does 100 Mbit/s; Your camera does 5 Mpixel; Blu-ray's 1x speed is 36 Mbit/s... All these "M" stand for 10^6, not 2^20.Nall
-1 I'm not sure I follow this answer. Which hard drive manufacturer made a definition? I don't think CodingHorror produces hard drives? I'm looking for an authority and a hard drive manufacturer would have too much bias to be objective.Coulometer
The "authority" supporting M=10^6 is the International Bureau of Weights and Measures. As far as I know, there is no "authority", besides custom, supporting M=2^20.Nall
#234575Nall
I'm not gonna downvote, but I'd point out that SI is kinda irrelevant in this case, because "megabyte" is technical jargon, and is conventional to the specific areas of computer science and engineering. If you want to cite IEC or other standards which adopt the SI definition purely for convenience or compatibility reasons, that's reasonable, though other standards may disagree. But the point is that "megabyte" will never equal 10^6 bytes simply because that's what SI says "mega", etc. means.Fougere
@IonoclastBrigham If you read the other answers, the IEC standard IS that mega means 10^6, not 2^20. They specifically have a different designation for that; mebi. So by all standards (not just what we colloquially call them) a Megabyte is 10^6 bytes and a Mebibyte is 2^20.Billie
C
9

for convert byte to megabyte(MB)

use totalbyte/1000/1000

for convert byte to mebibyte (MiB)

use totalbyte/1024/1024

https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

Carrier answered 24/4, 2022 at 2:9 Comment(0)
M
4

The answer is that #1 is technically correct based on the real meaning of the Mega prefix, however (and in life there is always a however) the math for that doesn't come out so nice in base 2, which is how computers count, so #2 is what people really use.

Makassar answered 2/3, 2010 at 18:18 Comment(0)
V
2

Megabyte means 2^20 bytes. I know that technically that doesn't mesh with the SI units, and that some folks have come up with a new terminology to mean 2^20. None of that matters. Efforts to change the language to "clarify" things are doomed to failure.

Hard-drive manufacturers use it to mean 1,000,000 bytes, because that's what it means in SI so they figure technically they aren't lying (while actually they are). That falls under lies, damn lies, and marketing.

Vocal answered 2/3, 2010 at 17:36 Comment(0)
M
2

Use the computation your users will most likely expect. Do your users care to know how many actual bytes are on a disk or in memory or whatever, or do they only care about usable space? The answer to that question will tell you which calculation makes the most sense.

This isn't a precision question as much as it is a usability question. Provide the calculation that is most useful to your users.

Misplace answered 2/3, 2010 at 17:49 Comment(0)
V
1

In general, it's wrong to use decimal SI prefixes (e.g. kilo, mega) when referring to binary data sizes (except in casual usage). It's ambiguous and causes confusion. To be precise you can use binary prefixes (e.g. 1 mebibyte = 1 MiB = 1024 kibibytes = 2^20 bytes). When someone else uses decimal SI prefixes for binary data you need to get more information before you can know what is meant.

Vieva answered 3/5, 2018 at 16:57 Comment(0)
W
0

Microsoft Windows Explorer shows file size in the "Properties" window. This is a conversion from the byte count using 2^20

Whose answered 3/1, 2023 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.