**Counting. **

The numbers we use everyday are known **decimal numbers** or **base 10**. Meaning there are 10 numbers ranging from 0 to 9. This translate to **10 ^{3} 10^{2} 10^{1} 10^{0 }**or 1000 100 10 1. So to write number 205, will be same as (1000x0)+(100x2)+(10x0)+(1x5) = 205.Or you can get the same result by division. Remainder is written on the right. Results read from bottom up. I know you know all this, but it just to refresh your memory.

Now for the fun stuff.

**Base 2**

In base 2 (**BINARY**), only 2 numbers are available for use. They are 0 and 1.

2^{7} 2^{6} 2^{5} 2^{4} 2^{3} 2^{2} 2^{1} 2^{0. }Which translates to 128 64 32 16 8 4 2 1. So to represent 205_{10} we will need (128x1)+(64x1)+(32x0)+(16x0)+(8x1)+(4x1)+(2x0)+(1x1). Which translate to 11001101. There is an easier method of doing this, division by 2.

So now eight base 2 numbers are used, that is to say 8 bits (**BI**nary digi**TS**).

Remainder is written on the right. The answer is read from bottom up. The number is written as 11001101_{2 }and in MikroC is written as 0b11001101_{. }**All binary numbers are represented by 0b prefix**. Simple isn’t it? For results with less than 8 bits, zeros are placed on the left of the answer until the bits count is 8. ie. result is 1100. Then result 00001100. Also good to know is that the **leftmost 4 bits are known as high order bits and the rightmost 4 bits are known as low order bits.**

__Some useful info.__

4 bits = 1 nibble

8 bits = 1 byte

16 bits = 1 word

**Base 8.**

Base 8 is known as **OCTAL**. The process of converting base 10 to base 8 is similar to the above example except you divide with 8. So lets convert 205_{10 to} base 8.

The answer is 315_{8} and octal numbers are represented in MikroE C by preceding the number with 0 (zero), which will be written as 0315. This number can be reversed to base 10 by 8^{2} 8^{1} 8^{0 }which is 64 8 1. So (64 x 3) + (8 x 1) + (1 x 5) = 205.

**Base 16**

In base 16, known as **HEX**, numbers 0 to 9 and letters A to F are used to represent the number. Because we cannot use a double digit number like 11,12 and so forth, the letters A to F is used to represent a double digit number, A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. Let’s convert 205_{10} to hex by dividing.

As you can see, we cannot write 12 and 13. So we change the number to their alphabet equivalent. So the answer will be **BC _{16}**. Again we can verify if the answer is correct by using the 16

^{1}16

^{0}. Which is 16 and 1. We know that B is 12 and C is 13, so (16 x 12) + (1 x 13) which gives us a decimal 205. Hex number is represented as 0xnn in MikroC. Our number will be written as

**0xBC**. The 0x tells the compiler that the next digits are hex number. If the division yields only one number, than a 0 precedes the number. ie. 0x0B.

That’s all there is to understanding base n. To convert a number from base 8 to base 2, firstly the number needs to be converted to base 10 then to base 2. There no calculation method to directly convert the number. I will present you later with the table to do exactly that.

Lets do some exercise so that base n sticks in our minds.

**Skill check Lesson 5.**

1. Convert to binary.

a. 10_{10} b. 255_{10} c. 101_{10} d. 68_{10}

2. Convert to decimal.

a. 10101100_{2} b. 10010011_{2} c. 01101111_{2} d. 1001_{2}

3. Convert to octal.

a. 252_{10} b. 97_{10} c. 18_{10} d. 127_{10}

4. Convert to hex.

a. 255_{10} b. 126_{10} c. 160_{10} d. 32_{10}

_{}

_{ }

_{}

_{ }

_{}

You can post your answers in the comments. Chat box might get confusing.