There are 10 types of people in this world: Those who can read binary and those who can't.

Many electronic and microcontroller projects require the use of a particular base numbering system, such as BCD on thumbwheel switches, hexadecimal (base-16) on hex encoders, and binary in shift registers and dip switches.  Often it is necessary to convert between bases, for example, when using a decade counter and converting a BCD value of a switch into a base-10 (that is, decimal) value that can be easily displayed.  In particular, all math is done in binary in digital systems, as well as at the analog/digital interface (like when you sample a waveform or measure a voltage) using only two digits: 1 and 0.

This is a brief instructable on what numbers represent and how to convert between the bases in which they are represented. This was included in one of my other guides when I realized that it should be separated out and put into its own instructable. After reading this guide you should be able to look at a binary number like "11101011" and tell that it represents the number 235 or convert the hex value "0xC0E4" to its binary equivalent of "1100000011100100" and decimal representation of 19980 without the use of a calculator (unless you suck apples at addition,subtraction,or division, in which case I feel your pain and wholly suggest keeping your favorite calculator handy).

However, no heavy math is needed and you won't need to do anything outside of basic math so don't sweat it if you're mathematically challenged.  This is part of the fun side of math.

Step 1: Understanding Number Representations

Have you ever wondered why we use 10 numbers in our everyday numbering systems, represented by the numbers 0 through 9, instead of, say, 8 or 17 or why it's so easy for us to count by fives (5,10,15,20...) instead of by sevens?  The bold fact is that humans have five fingers on each hand, totally 10 and our numbering system evolved from using our fingers to count up things.  I'd happily bet that if we had six fingers on each hand, it would be quite natural for us to have 12 numbers in our base numbering system, say, zero through Þ.  You've probably already groked this concept.

As just mentioned and you probably already knew, a number's base dictates how many numbers are used in the counting system.  The most common bases are discussed next, but before that a brief detour on what --conceptually--a number means.  Let's take the base-10 number, 28810

Note that I follow convention when a common base is not implied and explicitly state the base as a subscript to the number.

Decimal (base-10, or denary)

What does 28810 mean, exactly?  This value explicates that this number encompasses two 100's, eight 10's, and 8 units.  This can be succinctly shown as:

28810 = (2 * 100) + (8 * 10) + (8 * 1)


28810 = (2 * 102) + (8 * 101) + (8 * 100)

           =  200 + 80 + 8



htun = (h * n2) + (t * n1) + (u * n0) where h=hundreds,t=tens,u=units

As read across left to right, each number increases the total value by that number * base to the power of its place.  This notation will become useful when I show you how to convert any base into base-10/decimal in the next step.  There's not much to say about denary until a few more steps.

<p>And here you can find the formal math to convert number in any base to any other base: http://www.codinghelmet.com/?path=exercises/converting-number-bases</p>
<p>Hiyas,</p><p>Thanks for that link. Webpages that make use of latex math please me. :)</p>
<p>Alright, my question is about decimal to hexadecimal. When you have the number (9 in your example) and divide it by 16 and it equals 0, it works fine. But when you have a number like 429dec, which provides 26, which divides by 16 to 1, what do you do. I tried multiplying the equation by 1 and moving it over, and the converter showed a different result.</p>
Hi Zack, Ok, if I understand what you're unsure about, let's take the number you gave and work it out using my method.<br> <br> 429<sub>10</sub> = ???<sub>16</sub>&nbsp;<br> <br> 1. 429 / 16 = 26.8125; .8125*16 = 13; 13 in hex is D. So 0x??D<br> 2. 26 / 16 = 1.625; 0.625 * 16 = 10; 10 in hex is A. So 0x?AD<br> 3. 1 / 16 = 0.0625; 0.0625 * 16 = 1; 1 is 1 in hex, so 0x1AD.<br> 429(dec) = 0x1AD(hex)<br> <br> Hope that helped to clear it up. If you still have problems feel free to ask again.<br> Cheers and thanks for the comments!
<p>Hey guys,</p><p>Thanks for the comments. I checked and it looks like a typo as I have it correctly typed in the preceding line. The typo below is now corrected.</p><p>Thanks for finding that!</p>
<p><strong></strong></p><p>158 base 10 should be equal to 314 in base 7.</p>
<p>I second/confirm/approve of or whatever this statement.</p>
<p>Good Job. Please confirm the conversion of <strong>158 (Base 10) into base7 the result it should give is 314 (Base 7), not 214 (Base 7). </strong></p><p><strong>Just cross-check if there were any errors during calculations.</strong></p><p><strong>Weldone !!!</strong></p>
<br> You left out octal (base 8), which is just like base 10. If you're missing two fingers.<br> <div class="media_embed"> <a href="http://video.google.com/videoplay?docid=-7841878207694220233#">http://video.google.com/videoplay?docid=-7841878207694220233#</a></div> <br>
Oops, where did I leave out octal? <br><br><br>Ah, Tom Lehrer....
oops. I guess not. It was just missing from titles...<br>
where did you hear that joke from?
I think I saw it first on a thinkgeek t-shirt.

About This Instructable


22 favorites


Bio: Gian is a computational biologist and is the Managing Director at Open Design Strategies, LLC. He holds a BA in Molecular/Cellular Biology and an ... More »
More by nevdull: Create A Custom Medieval-/Fantasy-Style Calligraphy Quill Practical DACs Using Enumerated Types as Bitflags
Add instructable to: