How to Convert Between base-10, Hexadecimal, and Binary by nevdull
binary1.jpg
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.
 
Remove these adsRemove these ads by Signing Up

Step 1: Understanding Number Representations

denary.gif
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)

-or-

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

           =  200 + 80 + 8

 

Generalized:

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.



westfw says: Sep 22, 2010. 9:40 PM

You left out octal (base 8), which is just like base 10. If you're missing two fingers.

nevdull (author) says: Sep 22, 2010. 11:33 PM
Oops, where did I leave out octal?


Ah, Tom Lehrer....
westfw says: Sep 23, 2010. 9:51 AM
oops. I guess not. It was just missing from titles...
matstermind says: Sep 22, 2010. 11:48 AM
where did you hear that joke from?
nevdull (author) says: Sep 22, 2010. 1:05 PM
I think I saw it first on a thinkgeek t-shirt.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!