[**Update, April 13, 2007: **Thanks to Herr Ziffer for catching a confusing typographical error.]

I can’t believe I’d never seen (or figured out) this quick method for converting a binary number to a decimal number in your head. All you need to be able to do is double numbers and occasionally add one.

- Start at the first ’1′ on the left, and start with the mental number one
- Move one digit right. If that digit is a zero, multiply your mental number by two. If it is a one, multiply your mental number by two and add one.
- Repeat step 2 for every digit of the binary number

Here’s an example. We’ll use the binary number 1101010 1011010:

**1**011010 – We start at the first one. Our mental total: 1- 1
**0**11010 – Next digit is a zero; we double our mental number: 1 x 2 = 2. - 10
**1**1010 – Next digit is a one; we double our mental number and add one: 2 x 2 + 1 = 5 - 101
**1**010 – Another one; double and add one: 5 x 2 + 1 = 11 - 1011
**0**10 – Zero; double: 11 x 2 = 22 - 10110
**1**0 – One; double and add one: 22 x 2 + 1 = 45 - 101101
**0**– And finally a zero; double: 45 x 2 = 90

The rest of this post is a little more technical, so if you glazed over when reading the above, it now may be time to soothe your tired mind.

I happened across this trick while contemplating a three-state discrete finite automaton that identifies binary numbers divisible by three. The automaton starts in state 0, and like the above procedure starts at the left side of the number. The number of the state can be thought of as the remainder of the number as read so far, mod 3. Every time a zero or a one is read, the automaton follows the arrow with that label from its current state. If it ends in state 0, the number is evenly divisible by three. Once I understood why the DFA actually works, the mental calculation became glaringly obvious.

For even more fun, the regular expression (0*(1(01*0)*1)*)* will also match binary numbers divisible by three.

Exciting! Now you have something to talk about the next time you go to a cocktail party.

Thanks a lot buddy

You’re very welcome, Santosh. Thanks for reading.

Paul,

You had me scratching my head for ten minutes wondering why I couldn’t do the conversion. It appears you have a typo: “We’ll use the binary number 1101010″ should be “We’ll use the binary number 1011010″.

With this, I intend to startle my friends and seduce my enemies at the next cocktail party.

Thanks.

Aargh! I thought I’d triple-checked everything!

This is a good warning, though: misapplied, you can also use this trick to embarrass yourself publicly. Thanks, Herr Z.

Wow. Thanks. I am studying for CCNA and this just made life a whole lot easier.

thank you so much!! Will be very much helpful in my exam which is in 1 day time lol…

hey buddy u are simply great. please tell me the trick that how did u calculate the regu;ar expression is there any trick????

Hi, Sumitra. Regular expressions and discrete finite automata are equivalent; that is, they both are able to recognize the same class of “languages”. A theory of computation textbook should explain this equivalence in detail (Michael Sipser’s

Introduction to the Theory of Computation, for example). There are a lot of lecture slides online that explain the process of converting one to another….http://www.math-cs.gordon.edu/courses/cps220/Notes/regular_expressions.pdf gives a decent overview.Do you have any tips on converting Decimal to Hex or binary in head?

(please notify me via email, if you happen to have a solution)

Hi, AIbY,

This trick can be used in reverse for converting decimal to binary, but it’s harder to do mentally as the binary numbers tend to overflow your mental registers. If you try it, it’s best to use a piece of paper and write the binary number down as you go. You’ll be writing down the digits from right (least significant) to left (most significant).

So, the procedure looks something like:

1. Start with the decimal number in your head

2. Is the current decimal number divisible by 2?

a. If so, then write down

0b. If not, then write down

1and subtract 1 from the mental number.3. Divide your mental number by 2 and go back to step 2. Repeat until your mental number is

0.It’s easy to lose track of where you are in the conversion process, so jotting notes is helpful.

Directly applying this process to hexadecimal is even harder, as it relies on the ease of dividing by two. One possible approach would be to first convert your decimal number to binary as described above and then converting each set of four binary digits to hex, starting from the right…easy enough, just memorize your single-hex-digit-to-binary conversion table.

Hello,

First off I’d like to say, this is gold! I am studying for my CCNA and CCNP and your method will go a long way in helping me to succeed.

I have one question though.

I’ve tried to follow your steps with the decimal 55 and have had no luck with your convertion method. The binary I should end up with is “00110111″, but I endup with “010010101″. Can you please help me out with an example of how to do it? I think I’m doing it worng.

Thank you in advance!!

Regards,

Javier

JavierVV,

I hadn’t looked at this for a while, and I was confused myself for a minute!

The tricky thing in the way those steps are written is that step 3 (dividing the mental number by 2) is

alwaysperformed. After step 2, whether you’ve performed 2a or 2b, the mental number will always be even…so you’ll always be able to divide by 2 and get an integer as a result.Also, the digits are written from right to left…this means, for any positive integer, the last digit you write will always be a

1!So:

(2) -> 55 is not divisible by 2

(2b) -> new binary is

1, 55-1 = 54(3) -> 54/2 = 27

(2) -> 27 is not divisible by 2

(2b) -> new binary is

11, 27-1 = 26(3) -> 26/2 = 13

(2) -> 13 is not divisible by 2

(2b) -> new binary is

111, 13-1 = 12(3) -> 12/2 = 6

(2) -> 6 is divisible by 2

(2b) -> new binary is

0111(3) -> 6/2 = 3

(2) -> 3 is not divisible by 2

(2b) -> new binary is

10111, 3-1 = 2(3) -> 2/2 = 1

(2) -> 1 is not divisible by 2

(2b) -> new binary is

110111, 1-1 = 0(3) -> mental number is 0 and conversion is complete

The converted binary is, therefore,

110111.wow its very interesting and amazing this is very useful inspiring me for my education research…thanks Zanoli

WOW this is really awesome i have tried the method and its reverse

thanks Herr Ziffer

thanks Pual

But, I still dont understand how DFA works. Pls, explain it to me. Thank you very much.

Awesome Trick. Just Fabulous!

I know this was posted years ago, buuuuut, I’ve been struggling with learning binary to decimal in my UNI studies – the text book and lectures have confused me…and thanks to you I have NAILED it…if I could hug you I would…Jane.

Thanks for the hint! And you can do it to an auctioneer’s chant to make it stick. At least, that helps me keep track in my own head.

There’s a one, zero double it two. There’s a one, double it four, add one, now we’re at five. Five, there’s a one, double it ten and add a one, we’ve got eleven eleven. There’s an O, double it TWENNY two. Got a one, double it fourty four add one that’s fourty five, now a zero double it Ninety SOLD.

You Sir have just helped me pass an exam, much appreciated.

Just taught this to my academic teams. It will be used next week at the district contest. Many Thanks!

WOW you just saved my life. I was struggling to understand the conversion. Always been bad at math. But this trick makes it so easy.

Thanks

Sir,Thank you so much.Now i need to know the easiest way to converting from decimal to binary.it would be highly appreciate if you could do something for me….

Thank you. I got used to using ip calculators. Much easier to convert.

Thanks for the great trick! I needed this for taking the CCNA test as well.

One of the best binary conversion methods i’ve found. Thanks for sharing.