- C++ First Program
- C++ Data Types
- C++ Conditions
- C++ Booleans
- C++ Switch Statements
- C++ Loops
- C++ Functions
- C++ Pointers
- C++ Arrays
- C++ Data Files

Using base 2 can seem complicated at first but once explained it isn't too bad. In our everyday world we use base 10, values ranging from 0 to 9. Once we surpass 9 we add a 1 to the next digit and continue from 0 to 9. For example, we first count from 0 to 9 then add a 1, we then have 10, then count from 0 to 9 again only with a 1 next to it, 11, 12, 13, 14...once we get to 19 we simply once again add a 1 and start over, leaving us with 20. However, in base 2, instead of having a series of numbers from 0 to 9 we only have 0 and 1. So how the heck does that work? Lets look at a number in base 2, 110 which equals 6. Here is how.

110 = (2^2 * 1) + (2^1 *1) + (2^0 *0) = 4+2+0 = 6

Do you notice a pattern? Starting from the left, 2 is raised to the 2nd power because it is in the 3rd column, (2 will always be raised by 1 less than the column it is in) and then times by 1 because there is a one in the 3rd column. 2 is then raised by 1 because it is in the 2nd column and times by 1 because there is a 1 in the 2nd column. Finally 2 is raised by 0 because it is in the 1st column and times by 0 because it 0 is in the first column. Once you begin to realize this pattern the easier it is to decipher.

Since anything times 0 is 0 and anything times 1 is itself, try to think of the 0's and 1's as a switch. A switch that tells you whether or not to raise 2 to a certain power, depending on what column it is in. With this kind of logic it begins to become easy to decipher something like this 10110. Let's try!

1 0 1 0 0 2^4 0 2^2 0 0 = 16+0+4+0+0 = 20

Because base 2 uses powers of 2, by design a sequence of numbers emerge, you guessed it, the numbers just double!

2^0 = 1 2^1 = 2 2^2 = 4 2^3 = 8 2^4 = 16 2^5 = 32 2^6 = 64 2^7 = 128 2^8 = 256

Ok so lets try one more just for practice, 10001

1 0 0 0 1 2^4 0 0 0 2^0 = 16+0+0+0+1 = 17

Starting from the left, the first 1 is in the fifth column, so it's gonna be 2^4 which is 16. The next three columns are 0 so we won't doing anything with those. Finally the last 1 is in the first column so 2^0 which is 1. 16 + 1 equals 17, therefore 10001 = 17. There you have it! Here is quick reference guide of the first 20 values in base 2.

0 = 0 1 = 1 2 = 10 3 = 11 4 = 100 5 = 101 6 = 110 7 = 111 8 = 1000 9 = 1001 10 = 1010 11 = 1011 12 = 1100 13 = 1101 14 = 1110 15 = 1111 16 = 10000 17 = 10001 18 = 10010 19 = 10011 20 = 10100