1
$\begingroup$

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.

  • 1
    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.2012-06-22

2 Answers 2

2

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.

  • 1
    I have been away and plaid some more with this, and it has all made sense now. I have a working converter. Many thanks :)2012-06-23
3

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.

  • 0
    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 :D2012-06-23