Have you ever used the Windows calculator, changed the view to Programmer, and then stumbled across the Hex, Dec, Oct, and Bin options? Know what they mean? Well I'm gonna tell you anyway. In order, they mean Hexadecimal (Hex), Decimal, Octadecimal, and Binary. Welcome to computer math!

## Dr. J.

When I was in the eleventh grade, I was afforded the rare opportunity to learn heavy-duty computer stuff from a visiting college professor, Dr. J (not the basketball player). Think of Dr. J as having the same personality as Doc Brown from Back to the Future. Add glasses and a salt and pepper beard and you now have my mentor, Dr. J.

Dr. J's class was programming not only in BASIC and Pascal, but now we were programming in assembly language and machine language, thanks specifically to Dr. J. Our final exam with him was to design a video game on the Commodore 64 in assembly language, pretty much bypassing the OS, or ROM as it was called then! This is tough stuff, even by today's standards.

He also taught us how to do arithmetic in binary and hex, using only pencil and paper. (And yes, they did have calculators way back then.)

## Binary

Why does binary exist and what's it got to do with computers? Good questions. Something that is considered binary can only be in one of two states, on or off, up or down, and so on. In binary computer terms, on and off are represented by one and zero, respectively. This binary system is used because of the computer's CPU and its many transistors. For example, an Intel I7 Quad Core CPU consists of 731,000,000 transistors. Each transistor can either be on or off. The OS reads on or off as 1 or 0, hence the need for binary math.

Reading binary is simple but time consuming. 10010110 is a typical binary number. Notice it is made up of eight number places. Each number place is considered a bit. Hence, this is an 8-bit number. All eight numbers together are called a byte. Therefore, bits create bytes. Incidentally, the binary number 10010110 equals 150 in decimal format.

Look at the table below. Notice, from right to left, the header numbers double in value, doubling from 1 to 128. The numbered table headers indicate what a binary value of 1 represents in decimal format. Let's plug our example binary number into the table below to see how it translates to 150. Notice that if you add up all the table headers where a 1 lives, you get a total of 150 in decimal format. In other words, 128+16+4+2 = 150.

Now look at the second row below the header. The highest number allowed in an 8-bit binary number is 255. (I bet you've seen that number before.) Using the table below, you can get any decimal number from 0 to 255. The next two questions are obvious:

• How do I get a value higher than 255?
• What do the numbers mean?

1286432168421Total in Decimal Format
10010110150
11111111255

### How do I get a value higher than 255?

The simple answer is to add columns to the left. If we were to do that, the next columns would be headed with 256, 512, 1024, etc. Adding a total of eight more columns would allow you to produce 16-bit numbers. The highest 16-bit number is 65,535. Next would be 32-bit, 64-bit, and so on.

### What do the numbers mean?

Does the image below look familiar? 2,147,483,647 is the highest 32-bit number possible. In this case, it means my monitor can display a maximum of 11111111111111111111111111111111 colors, or, in decimal format, 2,147,483,647 colors.

Following is how the computer generates the letter A to your screen. Note the headers are the same as our table above. Each black box is a 1, while each white box is a 0. Each black box is also a pixel on your computer monitor that is turned on, in this case to display the letter A. I've highlighted in red the pixels that are turned on to display the letter A, as represented in binary form.

### The ASCII Character Table

Below is a portion of the ASCII Character Table. Highlighted in yellow is the letter A as represented in the different mathematical formats.

### More Questions

• What is ASCII?
ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'A' or '@' or an action of some sort.
• Why does A = 65 and 41 and 101?
These numbers refer to the ASCII table so the computer knows where to go.
• Who uses these numbers for anything when I can just type the letter A? And by the way, computers do more than just splash letters on the screen, buddy.
This is where Hex and Assembly language come into play. Stay tuned for Computer Math, part 10.