# How can I convert between powers for different number bases?

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"?

-
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

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.
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.