Episode 142: February 15, 2013
Real World Math
by Jason Marshall
Is it possible to always be able to guess a secret number between 1 and 1,000 in no more than 10 tries? Why do smart phones come with 16, 32, 64 or some other strange number of gigabytes of storage? What do both of these questions have to do with binary numbers? In part 1 of this series on binary number basics, we learned what binary numbers are and how you can represent a decimal number (the kind that you’re used to) in binary form. Now that we’re all up to speed on the nuts and bolts of binary numbers, this week we’re going to have a bit of fun using them to solve brain teasers.
Sponsor: This podcast is brought to you by Betterment.com
. Betterment offers users an easy way to invest. No prior investing experience is required. Users choose how to allocate their money between two pre-set baskets—a stock basket and a bond basket. Signing up takes less than 5 minutes, and money can be added or withdrawn at any time without a fee. Users who sign up at betterment.com/mathdude
will receive a $25 account bonus as long as their initial deposit is $250 or more.
Recap: What Are Binary Numbers?
As we learned last time, the binary system is the simplest number system possible. In contrast to the decimal system’s ten symbols (0 through 9), the binary system uses only two (0 and 1). In the binary system we start counting at 0, then continue to 1, and then—since we’re all out of new symbols—we add a digit to make the binary number ‘10’ representing the number made of one 2 and zero 1s…aka 2. After ‘10’ is ’11’ (or 3), then ‘100’ (or 4), then ‘101’ (or 5), ‘110’ (or 6), ‘111’ (or 7), and so on.
Each binary digit represents the next higher power of 2. So the far right digit represent 2^0=1, the next represents 2^1=2, then 2^2=4, and so on. All you have to do to figure out the decimal equivalent of a binary number is add up all the powers of 2 that have a ‘1’ in their place. For example, since the binary number ‘1010’ has ‘1’s in the 4th digit (representing 2^3=8) and the 2nd digit (representing 2^1=2), it’s equivalent to the decimal number 8 + 2 = 10.
How to Guess a Number Using Binary Numbers
I’m going to think of a number between 1 and 1,000 and I want you to guess it in no more than 10 tries.
Now it’s time for some fun. I’m going to think of a number between 1 and 1,000 and I want you to guess it in no more than 10 tries. Sounds tough, right? After all, there are 1,000 possible numbers…but you only get 10 guesses! Well, it would be tough if you were just randomly guessing, but the key to our game is that each time you guess I’m going to tell you if my number is higher or lower. As you’ll soon see, this little change makes all the difference in the world.
To demonstrate how it works, I’m going to let you in on the secret number I’m thinking of: 100. So, what should your first guess be? For reasons that will become clear, it should always be 512. If I say “higher” to that guess, you should take half of 512—which is 256—and add it to your previous guess to make a new guess: 512 + 256 = 768. But since my secret number is 100, I would have actually said “lower.” That means you should really take half of 512 and subtract it from your previous guess to get your new guess: 512 – 256 = 256. Since this is still larger than my secret number, I’d once again say “lower.” You should then subtract half of 256—the number you added or subtracted during the last round of guessing—from your previous guess. So your new guess should be 256 – 128 = 128.
For each subsequent guess, the idea is to cut the previous value that you added or subtracted in half, and then add (if your guess is too low) or subtract (if your guess is too high) this new value from your previous guess. For my secret number of 100, the sequence of guesses you should make are:
Guess: 512. Response: Lower. Calculate: 512 / 2 = 256. Then…
Guess: 512 – 256 = 256. Response: Lower. “Calculate: 256 / 2 = 128. Then…
Guess: 256 – 128 = 128. Response: Lower. Calculate 128 / 2 = 64. Then…
Guess: 128 – 64 = 64. Response: Higher. Calculate 64 / 2 = 32. Then…
Guess: 64 + 32 = 96. Response: Higher. Calculate 32 / 2 = 16. Then…
Guess: 96 + 16 = 112. Response: Lower. Calculate 16 / 2 = 8. Then…
Guess: 112 – 8 = 104. Response: Lower. Calculate 8 / 2 = 4. Then…
Guess: 104 – 4 = 100. Response: Bingo!
As you can see, you managed to guess my secret number in only 8 tries! And no matter what my number is, this method of guessing will always find it in no more than 10 tries.
What Do These Guesses Mean?
But what’s the method behind this apparent madness? Well, if you think about it, you’ll see that each number you added or subtracted from your previous guess was a power of 2. Which means that each of your guesses actually represents a digit in the 10-digit binary representation of my secret number. A response of “higher” to your guess means that the digit is a ‘1,’ while a response of ‘lower’ means that the digit is a ‘0.’ The end result of this clever sequence of guesses is my secret number…written in binary form! Who knew binary numbers could be so useful, right?
Phones, Computers, and Binary Numbers
Actually, a lot of people knew. Which is why the phone in your pocket has 8, 16, 32, or some other power-of-2 number of gigabytes of storage. As you probably know, computers store information in the form of something called bits (short for “binary digits”), each of which hold either 0 or 1. In order for the brain inside a computer to find and use these storage locations, they must be assigned an address (just as a house must be assigned an address for mail to be delivered to it). As it turns out, this process of assigning addresses works best if all of the addresses can be written as binary numbers. And in order for that to happen, there must be a power-of-2 number of bits. Which is exactly what your phone has!
But that’s not the only relationship between phones, computers, and binary numbers. In fact, the deeper you look, the more you find. As an example, next week we’re going to take a look at how computers use binary numbers to do addition. After which, you’ll finally understand how a brainless piece of plastic can add faster than you!
Okay, that’s all the math we have time for today. Remember to become a fan of the Math Dude on Facebook where you’ll find lots of great math posted throughout the week. If you’re on Twitter, please follow me there, too. Finally, please send your math questions my way via Facebook, Twitter, or email at email@example.com.
Betterment LLC is an SEC Registered Investment Advisor. Brokerage services are offered by Betterment Securities, an SEC registered broker-dealer and member FINRA/SIPC. Investments are not FDIC Insured. No Bank Guarantee. May Lose Value. Investing in securities involves risks, and there is always the potential of losing money when you invest in securities. Before investing, consider your investment objectives and Betterment's charges and expenses. Not an offer, solicitation of an offer, or advice to buy or sell securities in jurisdictions where Betterment and Betterment Securities are not registered.