Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a program to convert between megabits per second and mebibits per second; A user would enter 1 Mebibits p/s and get 1.05 Megabits p/s as the output.

These are two units of computer data transfer rate. A megabit (SI unit of measurement in deny) is 1,000,000 bits, or 10^6. A mebibit (IEC binary prefix) is 1,048,576 bits or 2^20.

A user will specify if they have given a number in mega-or-mebi bits per second. So I need to know, how can I convert between these two powers? If the user inputs "1" and selects "mebibits" as the unit, how can I convert from this base 2 number system to the base 10 number system for "megabits"?

Thank you for reading.

share|cite|improve this question
usually programming languages supply formatting options to output numbers in binary, octal, decimal or hexdecimal notation. If you only need an input output conversion this should be sufficient, since you are dealing with the same number all the time. – user20266 Jun 22 '12 at 16:18
To convert megabits to mebibits, you just divide by $1.048576$. To convert the other way, multiply by $1.048576$. What else do you need to know? – MJD Jun 22 '12 at 16:21
How did you work that out, 1.048576? – jwbensley Jun 22 '12 at 16:22
There are 1048576 bits in a mebibyte, and 1000000 bits in a megabyte, so there are 1048576/1000000 megabytes in a mebibyte, and that's 1.048576. – MJD Jun 22 '12 at 16:37
up vote 2 down vote accepted

If you have $x \text{ Mebibits p/s}$, since a Mebibit is $\displaystyle \frac{2^{20}}{10^6} = 1.048576$ Megabits, you have to multiply by $1.048576$, getting $1.048576x \text{ Megabits p/s}$. Likewise, if you have $y\text{ Megabits p/s}$, since a Megabit is $\displaystyle \frac{10^6}{2^{20}} = 0.95367431640625$ Mebibits, you have to multiply by $0.95367431640625$, getting $0.95367431640625y\text{ Mebibits p/s}$. Round up as necessary.

To find these conversion factors, you can see that a Mebibit is $2^{20}$ bits, and a Megabit is $10^6$ bits. Therefore a Mebibit is $\displaystyle 2^{20} \text{ bits} = \frac{2^{20}}{10^6} \text{ Megabits}$, and the other direction is analogous.

share|cite|improve this answer
I'm getting some excellent answers, but there is still one thing I don't understand. I perhaps misunderstood the problem so didn't ask the correct question; The user can chose any unit of measurement from giga/mega/kilo bits p/s and gibi/mebi/kibi bits per second, so I was hoping someone would explain the conversion between powers as I originally mentioned, so that I could apply the same math (scaled up or down) to all these units. Using the above examples, will the math be the same but when converting from 10 mebibits p/s to kilobits b/s it's simply also going to be 1000x the outcome? – jwbensley Jun 23 '12 at 11:30
I have been away and plaid some more with this, and it has all made sense now. I have a working converter. Many thanks :) – jwbensley Jun 23 '12 at 13:14

You seem to misunderstand what a 'base" means; as with all numbers in common usage in Western society, the number $1,048,576$ is in base 10. For reference, here is the relevant Wikipedia page. Remember that in "base $b$" notation, the string of digits $(a_n\ldots a_1a_0)$ denotes $$a_nb^n+\cdots+a_1b+a_0$$ so for example, $10,048,576$ denotes $$(1\times 10^7)+(0\times 10^6)+(0\times 10^5)+(4\times 10^4)+(8\times 10^3)+(5\times 10^2)+(7\times 10^1)+(6\times 10^0)$$ However, in base 2, the same number would be written $$1\underbrace{0000000000000000000}_{19\text{ zeros}}=(1\times 2^{20})+(0\times 2^{19})+\cdots+(0\times 2^0)$$ Now on to how to convert. Because $$1\text{ megabit}=1,000,000\text{ bits},\quad 1\text{ mebibit}=1,048,576\text{ bits}$$ if you have $1.048576$ megabits, you have $$1.048576\times (1\text{ megabit})=1.048576\times 1,000,000\text{ bits}=1,048,576\text{ bits}=1\text{ mebibit}.$$ If you have $\frac{1}{1.048576}$ mebibits, you have $$\frac{1}{1.048576}\times(1\text{ mebibits})=\frac{1}{1.048576}\times 1,048,576\text{ bits}$$ $$=\frac{1}{1.048576}\times1.048576\times 1,000,000\text{ bits}=1,000,000\text{ bits}=1\text{ megabit}$$ Thus, $1$ megabit equals $\frac{1}{1.048576}$ mebibits, and 1 mebibit equals $1.048576$ megabits, and to convert any other number of megabits or mebibits, just multiply: $$x\text{ megabits}=\frac{x}{1.048576}\text{ mebibits}$$ and $$y\text{ mebibits}=(1.048576\times y)\text{ megabits}.$$ In even more generality, if one "blah" equals $X$ "foos" and one "kwip" equals $Y$ "foos", then one blah equals $\frac{X}{Y}$ kwips and one kwip equals $\frac{Y}{X}$ blahs.

share|cite|improve this answer
Thanks for your great answer Zev, I found it a little confusing at first, but after reading talmid's and doing some sums for myself it has all made sense, and I understand yours now too. Thank you :D – jwbensley Jun 23 '12 at 13:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.