Free tech support / small logo


How do binary numbers work?

My teacher has told us to learn how to count in binary but I'm a bit lost. How is 100 only one greater than 11?


Dave's Answer:

Sounds like you've got a good computer science instructor there, asking you to figure out the basic number system that the tiny little CPU chips inside our computers use to keep track of everything from numbers to graphics, audio files to the latest movie release.

Turns out that there are four (reasonably) common numbering schemes that you can encounter on a computer system, though for obvious reasons most of them are reserved for programmers and hard core techheads.

The numbering system you're used to is called decimal, or "base 10". That means that each digit can represent ten different possible values. 0, 1, 2, 3... 9. Decimal numbers are built from the right to the left, so 35 is really 3*10 + 5 or, to be more proper, 3*(10**1) + 5*(10**0). 10**1 is ten raised to the first power, or ten. Bigger numbers break down more interestingly: 9353 = 9*(10**3) + 3*(10**2) + 5*(10**1) + 3*(10**0). The "9" is really 9*1000. You know that, you've probably just never seen it written this way.

The reason it's considered decimal, or base ten, is because we use 10 as the basic value that we're factoring.

Take that same smaller number, 35, and use an octal, or base 8, numbering system and you find that it represents 3*(8**1) + 5*(8**0) or 3*8 + 5 = 29 (base 10). Does that make sense? You couldn't have 9353 in octal, however, because each digit can only represent the values 0,1,2..7, just as you can't have a single digit represent the value 10 in decimal.

Octal isn't used much any more, actually, but what you do still see as a software developer are both binary (base 2) and hexidecimal (base 16). (did you notice the pattern? Binary, octal and hexidecimal are all based on powers of 2. It's not an accident)

These are considerably more complicated, and a single hexidecimal digit can represent the values 0,1, 2, 3...9, A, B, C, D, E, F where "A" = 10 decimal, "B" = 11 decimal and so on. So a hexidecimal value like F2 is actually F * (16**1) + 2 * (16**0) or 15*16 + 2 = 242.

Let's focus on binary, though, as that's what you're asking about. Binary is the essential counting system of computers because as a base 2 numbering system, each digit can be represented electronically as on or off. 1 or 0. This means that binary numbers can get really long, really fast.

For example, 100 binary = 1*(2**2) + 0*(2**1) + 0*(2**0) = 4 + 0 + 0 = 4. 1000 = 1*(2**3) = 8, and so on. To count from 1-10 decimal in binary, the values look like this: 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010.

Want to represent 35 in binary? It's hard to calculate by hand, the answer is: 100011. Let's get more scary. How about 9353 as binary? 10001110010010001001.

By contrast, hexidecimal is more compact, as we've already learned, so that same value 9353 in "hex" is represented as 253F. Let's go bigger. 126,334,307 base 10 = 787b563 base 16.

Where this all gets interesting is when you start trying to work with what's called irrational numeric bases like pi or e, but that's a subject for another posting.

I hope this helps you out!


Also check out:








Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments (4) · Add Comment

That's a very interesting way to explain the different numbering schemes. It's probably the right way to do it too from a mathematics standpoint. However, I personally like to think of binary as a set of switches with different values since the number can only be a 0 or a 1 (0 being off and 1 being on).

Starting from the very right (moving right to left), each switch is worth twice as much as the previous switch. We start with the very first switch on the furthest right having a possible value of 1. If this switch is on (set to 1), then it's worth 1, if it's off (set to 0) then it's worth 0. The next switch to the left of the first one is possibly worth 2. If this is on (set to 1) then it's worth 2, if it's off (set to 0) then it's worth 0.

The following switches are then possibly worth 4, 8, 16, 32, and so forth. Simply add up all the values of the switches that are on and you'll get the value of the binary number in decimal.

For example: 10011101 would be the equivalent of 1+0+4+8+16+0+0+128 = 157
(Remember to read the values from right to left)

Just thought I could bring a different way to look at binary to help your readers.

Posted by: Derek at October 26, 2010 11:17 AM

Can you explain the ** operator? I haven't come across it before (which is odd because I have come across ++ and xor).

Posted by: Nathan at October 26, 2010 5:53 PM

Oh, sorry, Nathan, the "**" is a power operator, so 4 squared is 4**2. In other words, "to the power of" if you're reading it out loud. Some mathematical notations use "^" instead, as in "4^2".

Posted by: Dave Taylor at October 26, 2010 6:16 PM

Thank you for explaining it dave, that clears things up.

Posted by: Nathan at October 26, 2010 8:34 PM
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.