>How does binary code work...?
Binary is really just an alternative represention for numbers. Normally we use base ten to represent numbers, where the ten digits are:
0123456789
In binary (also known as base two), there are only two digits:
01
This makes things somewhat easier, since you don't have to worry about multiple positive values, you just have 1 and 0 for every digit.
For instance, let's say you wanted to represent the number 14 in binary. You would do it as follows:
- 14 is less than 16 and greater than 8, so we start at digit 4.
- 14 contains 8, throw away 8 to get 6 and put a 1 at place 4 for 1000.
- 6 contains 4, throw away 4 to get 2 and put a 1 at place 3 for 1100.
- 2 contains 2, throw away 2 to get 0 and put a 1 at place 2 for 1110.
- Now we have 0 so there is nothing more to take away.
This gives us 1110 as the binary representation of the decimal number 14.
Now let's add 29 to 14 in binary. Using the same method, we get 29 to be 11101 in binary. Now we add as follows:
- Compare the digits at place 1, get 0 and 1, add to get 1 and put that in place 1 for 1.
- Compare the digits at place 2, get 1 and 0, add to get 1 and put that in place 2 for 11.
- Compare the digits at place 3, get 1 and 1, add to get 10, put a 0 in place 3 for 011 and carry the 1.
- Compare the digits at place 4 and the carry, get 1, 1 and 1, add to get 11, put a 1 in place 4 for 1011 and carry the 1.
- Compare the digits at place 5 and the carry, get 1, 0 and 1, add to get 10, put a 0 in place 5 for 01011 and carry the 1.
- All the original digits above place 5 were 0, so put the carried 1 in place 6 for 101011.
So 29+14 translates to binary as 1110+11101 and the answer to this is 101011. Converting back into decimal, we see that this equals 43 exactly as intended.
>How can simple zeros and ones tell a computer what to do?
That is taken care of on a hardware level. Simply put, a computer has two main components, the processor and the memory. The processor stores values in sections called 'registers' located in hardware outside of memory. One of those registers contains a memory address for the next instruction. On each cycle, the processor looks into memory at that address, retrieves the information stored there, interprets that information in a way defined by the hardware in order to (possibly) carry out some single instruction, and finally increments the value in the aforementioned register by 1. Then the next cycle is started, and so on. A typical modern computer executes several billion of these cycles every second.
>Do any programmers learn binary, or is something like C++ perfectly capable of allowing for lots of programming opportunities without going any lower level.
C++ is very powerful, more powerful than some other common languages like Java. Just about anything you need to do can be done in C++. And 99.9% of the time a programmer in the real world spends writing code, they will be writing it in some higher-level language like C++, C, Java, PHP, or whatever.
However, there are still cases when programmers may need to use Assembly code, and any professional programmer will have some understanding of some Assembly language. Assembly is not literal 1s and 0s as the processor reads them, but it is very close; it is basically an abstracted version of machine code (the real 1s and 0s), such that each line of Assembly corresponds to exactly a single machine code instruction. And occasionally, a programmer may need to know the machine language as well, particularly if they are trying to hack into a system.