Saturday, September 4, 2010

Quick Binary Tutorial


People seem to freak out when they see binary. School math classes come flooding back and their mind freezes up. But there's no need for this at all. Don't think of binary as being difficult, just thing of it as different!

Binary terminology

Binary is a number system based on switches called bits. First, some terminology:

  • Each bit is switch.
  • Four bits is called a nibble.
  • Eight bits is called a byte.

If the switch is on, the value of the switch is 1. If the switch off, the value of the switch is 0.

Why people find binary "different"

There are few things about binary numbers that make them different to the plain vanilla decimal (base10) numbers that surround us every day.

  1. Binary only uses two of the digits that we are used to - 0 and 1
  2. We need to learn to read them right to left (like decimal the smallest or least significant bit is on the right)

So, step 1 to binary success is to accept point 1 and just accept point 2!

Understanding binary

In these examples we will work with 8-bit binary - that is bytes. You can work with larger or smaller units but the byte is the most commonly used one.

OK, let's take a look at a byte of binary

01101101

OK, so the first thing to remember is to read the byte from right to left. Let's make things easier by creating a table:


Switch
On = 1
Off = 0
01101101
Bit Position87654321
Bit Value in decimal1286432168421


Bit position is simply the position of the bit from the right - the bit furthest to the right is bit 1 and the bit on the left is number 8.

Decimal value of a bit is dependant on the position of the bit in the byte. The decimal value of the first bit is 1, the second 2 and so on. The eighth bit has a decimal value of 128. Converting a byte into decimal is simply adding up the decimal values of each on bit in the byte.

Highlight all the on bits and ignore the off bits:


Switch
On = 1
Off = 0
01101101
Bit Position87654321
Bit Value in decimal

128

6432168421
01101101 = 64 +32 + 8 +4 + 1


Bit 8 = 0

Bit 7 = 64

Bit 6 = 32

Bit 5 = 0

Bit 4 = 8

Bit 3 = 4

Bit 2 = 0

Bit 1 = 1





No comments:

Post a Comment