00:25 The funky collection of lines on the right is the circuit diagram symbol for a transistor. When an electrical charge is applied to the transistor’s base, current can flow through the transistor between the collector and the emitter.
00:46 Transistors are small switches. Apply a charge, and the switch is on. Remove the charge, and the switch is off. By changing the charge to different values on a series of switches, you can form a pattern.
Even Mona Lisa’s sly smile on your screen is really just a large array of these numbers. Each pixel in the picture is represented by a number. This drab-looking square of greenish is the hexadecimal number
7F8053. The hex number breaks down into three parts: the red, green, and blue that make up the color.
02:33 So, what is this binary number stuff? Let’s take a quick detour and think about the numbers you probably know a little better: decimal. Consider 4,239. This number can be broken down into four parts: 4,000 plus 200 plus 30 plus 9.
02:55 Each of these numbers can be thought of as the combination of a number and a power of 10. With 1000 being 10 to the 3, 100 being 10 squared, 10 being—well—10, and the ones digit being 10 to the 0.
03:12 Although base-10 feels right or special to us, that’s just because it is what was taught to us at a young age. There’s an argument that base-10 really only exists because of the number of fingers we have.
03:23 Historical civilizations have used different bases. The Babylonians used base-60, while the Mayans employed two different bases, base-20 and base-360, depending on whether you were a priest or not.
03:36 Those might seem kind of crazy, but they actually make math with numbers like 12 easier. How many hours on a clock? How many degrees in a circle? Yep, you’re using more than just base-10 yourself.
03:52 A number can have any integer base. Commonly in mathematics, the subscript here indicates the base. 4,239 base 10 is subscript 10. 4,239 base n has subscript n. For the general case of base-n, each digit is a power of n. 4,239 base n is 4 times n cubed plus 2 times n squared plus 3 times n plus 9 times n to the 0. Note that no digit in a base-n number can be larger than n itself. In base-10, each digit must be less than 10.
05:15 In computer science, there are four bases that are commonly used: decimal because that’s what humans are used to, binary because that’s what the machines want, and the last two are things that translate back and forth to binary easily—octal, which is base-8, and hex, or hexadecimal, which is base-16. Both octal and hex map to binary values, and with a bit of practice, you can convert them in your head.
5 in decimal is 4 plus 1, giving
0101 in binary, 2 squared plus 1. Octal, or base-8, allows for digits to be up to and including 7. So decimal 5 is also 5 octal. Hex, or base-16, allows for digits up to 15 in decimal. So one more time, the answer is also 5. Let’s try another one. 8 in decimal is 2 cubed, so the fourth bit is on. 8 decimal is bigger than the maximum value of a digit of 7 in octal.
06:20 So just like the other bases, you add a digit and roll the counter over. Or, going the math route, 10 octal is 1 times 8 to the first power plus 0. In hex land, you’re still under 15. So far, the conversion from decimal to hex is pretty simple. It will get worse, I promise. Let’s add 1 more to our 8 and get 9.
06:44 I didn’t even have to use my fingers. Adding one in decimal means adding one more in binary as well, so the first bit position increments. Adding one more to the octal value so the digit goes up by one, and good old hex still isn’t complicated.
07:02 It’s coming, wait for it. This time, I’ll add two more to the decimal value. And that means incrementing the binary value by 2. That’s a power of 2, so in this case, just turn on the second position. Two more to the octal case still hasn’t exceeded the max digit, so 11 octal becomes 13 octal. Notice that I don’t call these 11 and 13. 11 and 13 are decimal concepts. For clarity, I will try to remember to keep using the digit style.
Hexadecimal is base-16. That means the largest digit can be the equivalent of 15. How do you represent 15 as a single digit? You switch to the alphabet. 10 decimal is
A in hex. 11 decimal is
B in hex.
It is a convenient short-form for binary.
1011 is decimal 11, or
B in hex, and
0101 is 5 in both decimal and hex. If you have the binary equivalent of the sixteen digits of hex memorized, you can quickly substitute one value for another. Fun fact—and this is the problem with my sense of humor, you’re never going to believe what I’m about to say is true—half a byte—that’s four bits or a single hex digit—is called a nibble.
Become a Member to join the conversation.