Computers are composed of many working parts. Some parts communicate directly to the user such as the screen and speakers. Other parts allow the user to communicate to the computer, such as the keyboard and mouse. Internally, a computer has many parts that we usually do not see, such as the central processor and main memory. These parts play important roles in the functioning of a computer.
| Part | Role | Description |
| Screen | Output | Displays visual images, including text, pictures, and videos. |
| Speakers/Headphones | Output | Produces sound, including music, voice, and sound effects. |
| Keyboard | Input | Used for entering text. |
| Mouse | Input | Used for moving a cursor across a screen. |
| Central Processing Unit (CPU) | Internal | Carries out most of the calculations necessary for a computer to function. |
| CPU Core | Internal | A component of a CPU that carries out single calculations - one at a time, billions of times a second. |
| Graphics Processing Unit (GPU) | Internal | Carries out most of the calculations necessary to display images. The GPU is designed to carry out many calculations simultaneously. |
| Random Access Memory (RAM) | Internal | Often just called "Main Memory", temporarily stores data used by computer programs while the program is running. When the computer is turned off, this data is lost if it is not saved to a the Hard Drive. |
| Cache | Internal | Temporary memory storage similar to RAM, but smaller and more closely integrated with the CPU. Much faster than RAM, but the Cache cannot store as much data as RAM. Data is lost when the power is shut off. |
| Part | Role | Description |
| Motherboard | Internal | A major part of the computer containing the CPU, Cache, RAM. The motherboard of a computer is connected to almost every part of a computer. |
| Video Card | Internal | Another major part of the computer containing the GPU and memory used for graphics. |
| System BUS | Internal | The system bus is responsible for transporting data between the different parts of a computer and is composed of multiple types of buses. |
| Hard Drive | Internal | Built into the computer. Used for long term storage of data. When the power is shut off to the computer, this data is not lost. |
| Portable Memory Drive | Internal and External | Although not a permanent part of the computer, a portable memory drive, such as a usb drive, is an important tool for transporting data between computers. Data is not lost when the power is turned off. |
As we have seen, computers can store information (data) in the form of numbers and strings (text). Computers can also store images and sound. All of this data is represented in a computer as binary code. Much of the rest of this chapter is about how these types of data are represented as binary code. For now, lets consider what binary code is and how it is physically stored in a computer.
Binary code is traditionally represented as a sequence of 1's and 0's. In reality, it is any sequence that alternates between two possibilities. A typical short sequence of binary code could look like:
| Technology | Examples | Description |
| Integrated Circuit | CPU, GPU, RAM | Typically a sequence of two voltages across a circuit is used to transmit data. One of the two possibilities is usually close to zero voltage, the other is usually a small, but detectable, voltage. All voltages go to zero when the power is off. |
| Compact Disk | CD, DVD | Uses sequence of Microscopic Pits and Mirrors that either reflect lazor light or do not. |
| Magnetic Recording | Most Hard Drives, Cassettes, Magnetic Strips | Uses sequence of Microscopic Magnets that are aligned north-to-south or south-to-north. The alignment of the magnets remains when the power is turned off. |
| Flash | USB Drives, Some Hard Drives | This technology is capable of holding electrical charges in many microscopic components even when the power is off. |
| Part | Role |
| Hard Drive | |
| CPU Core | |
| Cache | |
| Keyboard | |
| Video Card | |
| Central Processing Unit (CPU) | |
| Mouse | |
| Video Card | |
| Speakers/Headphones | |
| System BUS |
| Cache | _____ Often just called "Main Memory", temporarily stores data used by computer programs while the program is running. |
| Hard Drive | _____ Displays visual images, including text, pictures, and videos. |
| CPU Core | _____ Produces sound, including music, voice, and sound effects. |
| GPU | _____ Used for moving a cursor across a screen. |
| Video Card | _____ Carries out most of the calculations necessary for a computer to function. |
| Portable Memory Drive | _____ A component of a CPU that carries out single calculations - one at a time. |
| Mouse | _____ Carries out most of the calculations necessary to display images. |
| RAM | _____ Used for entering text. |
| Screen | _____ Temporary memory storage similar to RAM, but smaller and more closely integrated with the CPU. Much faster than RAM. |
| System BUS | _____ Built into the computer. Used for long term storage of data. When the power is shut off to the computer data is not lost. |
| CPU | _____ Another major part of the computer containing the GPU and memory used for graphics. |
| Motherboard | _____ Is responsible for transporting data between the different parts of a computer. |
| Speakers/Headphones | _____ A major part of the computer containing the CPU, Cache, RAM. |
| Keyboard | _____ Not a permanent part of the computer and is an important tool for transporting data between computers. |
| Flash | ____ Uses sequence of Microscopic Magnets that are aligned north-to-south or south-to-north. |
| Compact Disk | ____ This technology is capable of holding electrical charges in many microscopic components even when the power is off. |
| Magnetic Recording | ____ Typically a sequence of two voltages across a circuit is used to transmit data. |
| Integrated Circuit | ____ Uses sequence of Microscopic Pits and Mirrors that either reflect lazor light or do not. |
Although it can take some getting used to, the way a non-negative integer (whole number) is represented with binary code is in many ways similar to the way an integer is represented in the decimal system. It should be noted that while this lesson focuses on non-negative integers, negative integers and floating point numbers are also represented with binary code.
Almost everyone in the world learns the decimal system in their elementary school years. In the decimal system, a number is represented with a sequence of digits representing different quantities. The number
As we know, the decimal system uses 10 digits:
The binary number system works by the same principles as the decimal system. The main difference is that in binary there are only two digits:
Because there are only two digits, instead of a ten's place there is a two's place. Instead of a hundred's place there is a four's place. However, just like the decimal system there is one's place. So the binary number
In the decimal system, the different place values, such as the ten's place, the hundred's place, the thousand's place, and so on..., are all equal to 10 raised to different exponents. An important math fact: n0 = 1 for any number n, except 00 which is undefined.
| Place Value | Exponential Form | Name |
| 1 | 100 | One's Place |
| 10 | 101 | Ten's Place |
| 100 | 102 | Hundred's Place |
| 1000 | 103 | Thousand's Place |
The placement of a digit tells us the quantity that the digit represents. For example, the 3 in the number 30 represents 3 times 10 because the 3 is in the ten's place. The binary system has place values based on the powers of 2.
| Place Value | Exponential Form | Name |
| 1 | 20 | One's Place |
| 2 | 21 | Two's Place |
| 4 | 22 | Four's Place |
| 8 | 23 | Eight's Place |
| 16 | 24 | Sixteen's Place |
| 32 | 25 | Thirty Second's Place |
To convert from binary to decimal, the following steps can be used.
It is a little tricker to turn a decimal number into a binary number. One approach is to take the number you wish to convert and repeatedly divide by two and find the remainder each time. When dividing by two the remainder is always 0 or 1. The remainders you find become the binary digits. However, the order we find the digits is in reverse. We will find the one's place first, then the two's place, and so on...
In almost all electrical devices, binary code is organized into units called bytes. You may have used terms like megabyte and gigabyte when discussing the sizes of files or how large a hard drive is. When we use these terms we are really discussing quantities of bytes.
Although it is much more common to use bytes to discuss an amount of binary code, a byte is not the smallest unit. A bit is actually the smallest unit and stands for binary digit. A bit is a single 1 or 0. A byte is 8 bits. A typical byte looks like:
| Number | Byte |
The largest integer that can be stored in a single byte is 255. That may seem like a strange number, but 255 is 1 less than 256 which is 28. The binary representation of 256 is
To discuss the size of a file or the memory capacity of an electronic device, we typically use prefixes such as kilo-, mega-, giga- tera-. These prefixes stand for different quantities. Unfortunately the quantities that these prefixes stand for is not completely consistent. For example, the prefix kilo- can either stand for 1000 or 1024 (which is equal to 210). Frustratingly, the memory capacity of RAM is typically measured as multiples of 1024, while the memory capacity of a hard drive is measured in multiples of 1000. Because 1000 is close to 1024, the distinction is usually not very important. There are alternate naming conventions, however these are not very commonly used outside of the computer industry. Most people have probably never heard of a mebibyte or gibibyte, but these refer to prefixes using multiples of 1024.
| Prefix | Value | Alternate Value |
| kilo | 1000 | 1024 |
| mega | (1000)2 | (1024)2 |
| giga | (1000)3 | (1024)3 |
| tera | (1000)4 | (1024)4 |
| peta | (1000)5 | (1024)5 |
| Decimal System | _____ Binary Digit |
| Binary System | _____ Unit of 8 individual 1's or 0's. |
| Byte | _____ Multiple of 1000 or 1024. |
| Bit | _____ Multiple of (1000)3 or (1024)3 |
| giga | _____ Number system using 2 digits. |
| kilo | _____ Number system using 10 digits. |
| Binary | Decimal |
| Decimal | Binary |
| Decimal | Byte |
The hexadecimal number system is another commonly used number system similar to the decimal and binary number systems. While the decimal system is base 10 and binary is base 2, the hexadecimal number system is base 16.
The main advantage of the hexadecimal number system is that it is easier to read than binary and hexadecimal numbers can be easily converted into binary and binary can be easily converted into hexadecimal. Hexadecimal to decimal and decimal to hexadecimal are trickier conversions. However, the algorithms we used for binary numbers are largely the same, but with a different base.
In any number system similar to the decimal system, such as binary and hexadecimal, every digit must be represented by a single symbol. The symbols we use for the decimal system are the familiar: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Recall that 10 is not represented by a single digit, despite the fact that this is the base 10 number system. The digits of binary are just: 0, 1. For hexadecimal we need 16 digits, however the only digits traditionally used are 0-9. So computer scientists and electrical engineers use the letters A-F to represent 10-15. In this way we have all of the 16 digits, 0-F, that we need.
| Digits | Quantity |
| A | 10 |
| B | 11 |
| C | 12 |
| D | 13 |
| E | 14 |
| F | 15 |
A typical hexadecimal number looks like
As was mentioned, converting from hexadecimal to binary and binary to hexadecimal is relatively easy. This is one of the advantages of hexadecimal numbers. We do the conversion by converting the hexadecimal digits to binary first.
| Digit | Quantity | Binary | Digit | Quantity | Binary | |
| 0 | 0 | 8 | 8 | |||
| 1 | 1 | 9 | 9 | |||
| 2 | 2 | A | 10 | |||
| 3 | 3 | B | 11 | |||
| 4 | 4 | C | 12 | |||
| 5 | 5 | D | 13 | |||
| 6 | 6 | E | 14 | |||
| 7 | 7 | F | 15 |
Now comes the easy part: to convert
| Hexadecimal | Binary |
First, break up the binary number into 4 digit segments, then look up the hexadecimal digit. Put 0's in front of the first segment if you need to in order to have 4 binary digits. So
| Binary | 4 Digit Segments | Hexadecimal |
Converting to decimal numbers is not as straight forward. Like with binary and the decimal system, the hexadecimal system uses place value. For hexadecimal, the place values are 16 raised to different exponents.
| Place Value | Exponential Form | Name |
| 1 | 100 | One's Place |
| 10 | 101 | Ten's Place |
| 100 | 102 | Hundred's Place |
| 1000 | 103 | Thousand's Place |
| Place Value | Exponential Form | Name |
| 1 | 160 | One's Place |
| 16 | 161 | 16's Place |
| 256 | 162 | 256's Place |
| 4096 | 163 | 4096's Place |
Recall, for the decimal number 348, we can decompose the number as follows:
Hexadecimal works in the same way, except the base is 16. So the hexadecimal number
Hexadecimal is frequently used to represent the data stored in bytes. This includes colors. For example in HTML, the color red is represented by
| Hexadecimal | ____ A single symbol used to represent a quantity. |
| Decimal | ____ The base 2 number system. |
| Binary | ____ The base 16 number system. |
| Digit | ____ The base 10 number system. |
| Hexadecimal | Binary |
| Binary | Hexadecimal |
| Hexadecimal | Decimal (Regular Numbers) | |
Recall that a string is really just a sequence or "string" of symbols, punctionation marks, blank spaces, and other formating markers. In order to represent this information inside of a computer, for example in RAM or in a Hard Drive, computer scientists have come up with a simple system: each symbol or marker is represented by a number (an integer) and that number is stored in binary code. All letters, symbols, punctionation marks, blank spaces, and other formating markers, which are generally called characters, are all stored as positive integers. So, in memory, strings are just sequences of numbers.
Every character has its own unique integer. There are two common conventions that are used in the English speaking world. The older convention is called ASCII and it has the Latin alphabet, the alphabet we use in English (a-z). There are also letters with accent marks, as well as punctuation marks, numberical symbols for digits (0, 1, 2,... ), and whitespace markers such as the space created by hitting the space bar or the tab key are also characters.
The newer and much larger set of symbols is called Unicode. Unicode has almost every symbol used in spoken languages around the world. If you can name a language, then it is overwhelming likely that the symbols used in that language are represented in Unicode. There are also other conventions used for character sets, such as for Chinese, Cyrillic, Arabic, and Greek. Many of these existed before Unicode was created.
ASCII stands for American Standard Code for Information Interchange. In ASCII, every character is represented by a single byte, whether it is a letter, whitespace, etc. The byte for a given character can be converted to a number. The capital letters, A-Z, are represented by the numbers 65-90 and the lower case letters, a-z, are represented by the numbers 97-122. The digits, 0-9, are represented by the numbers 48-57.
| Character | Number | Byte |
It may seem strange to think that the digit 0 is represented by the number 48 and the byte
Lets take a second to consider what is actually going on inside of a computer. Everytime text is typed by the user of a computer, then the corresponding number is stored somewhere in RAM. If using ASCII, everytime the user types the lower case letter g, then somewhere in RAM is the byte
The main difference between Unicode and ASCII is that the number of bytes used to store characters in Unicode is generally greater. Unicode was designed to be consistent with ASCII. So, Unicode uses the same numbers as ASCII to represent any characters that are also part of the ASCII system. However, because Unicode can represent so many more characters, some characters may take up to 4 bytes to store. For example, the Chinese character for the Moon is 月 and is represented by 26376, which takes at least 2 bytes to store. The two bytes are
Fonts contain the actual images that are shown on the screen or that appear on paper when text is printed. When text appears on the screen, a font must be used by whatever application is displaying the text (Word, Pages, Google Docs, Notepad, Gedit, etc.). Fonts are essentially lists of numbered images representing symbols. When an application is displaying text, it reads the list of numbers representing each of the characters. For each character, the application looks up which image to display in the font being used.
Fonts, at least normally, contain the correct image for the character that they are supposed to display. However, there is nothing about the hardware of a computer that prevents completely different images being displayed. For example, the Microsoft font Wingdings displays a variety of different symbols and images instead of the ordinary letters and digits.
| Character | _____ A numbered list of images usually of letters, punctuation marks or other symbols. |
| ASCII | _____ An individual symbol, including letters, punctuation marks, symbols used in other languages. |
| Unicode | _____ An newer and more complex system for assigning characters to numbers that includes a much larger list of characters. |
| Font | _____ An older and simpler system for assigning characters to numbers. |
| Bytes | String |
Colors can be created on a computer screen in a way that is similar to creating colors with paint. You may have learned in an art class of the primary colors and of the color wheel. Just as with paint, colors on a computer screen can be combined to create new colors. One major difference is that the rules for combining colors on a computer screen are different than with paint. For example, if blue paint and yellow paint are mixed, green paint is produced. This does not happen with a computer screen. Instead if blue and yellow light are combined, white or gray would be produced.
The primary colors of light are red, green, and blue. Yellow has been replaced by green. On a computer screen different amounts of the primary colors of light are shown at the same location on the screen. When two colors of light are combined, the resulting color is brighter because there is more light overall.
Paint absorbs colors other than the color of that paint. So when ordinary light containing all of the colors is shown on an object painted blue, all of the colors except blue are absorbed. The object appears blue because that is the color that reflects back. So when different colors of paint are combined more light is absorbed and the resulting color is darker.
Some of the rules for combining light may surprise you. Below, "half" refers to the color being at half brightness or intensity.
| Mixed Colors | Resulting Color |
| Red + Green | Yellow |
| Half Green + Red | Orange |
| Green + Half Red | Olive |
| Red + Blue | Magenta |
| Half Red + Half Blue | Purple |
| Green + Blue | Cyan |
| Half Green + Half Blue | Teal |
| Red + Green + Blue | White |
| Half Red + Half Green + Half Blue | Gray |
| No Light | Black |
Opinions on some of the color names may vary. For example, some may say Olive is half green light and half red light. However, the colors Yellow, Magenta, and Cyan are very commonly considered to be mixtures of red, blue, and green at full intensity. White is the combination of all of the colors at full intensity. Gray is produced when all of the colors are combined with the same relative amount, but at lower intensity. Different shades of gray can be produced by varying the light intensity. Black is the absence of light. If a part of your computer screen is black, such as text, then your screen is not shining any light, as though your screen was turned off, at least at those spots.
The RGB system is a way of representing a color with different integer values for the different amounts of red, green, and blue light. Although there are different conventions, one very common convention is to use a single byte for each of the three primary colors of light. Recall that the largest integer that can be stored in a single byte is 255. So white could be represented by the 3 numbers (255, 255, 255). In the RGB system the order is always (RED, GREEN, BLUE). So red can be represented by (255,0,0), and blue by (0,0,255). When smaller numbers are used we can get colors such as orange, which is (255,128,0). The number 128 is about half of 255.
| Color Name | RGB Representation |
| Red | (255,0,0) |
| Green | (0,255,0) |
| Blue | (0,0,255) |
| Yellow | (255,255,0) |
| Magenta | (255,0,255) |
| Cyan | (0,255,255) |
| Orange | (255,128,0) |
| White | (255,255,255) |
| Light Gray | (192,192,192) |
| Gray | (128,128,128) |
| Dark Gray | (64,64,64) |
| Black | (0,0,0) |
Of course many other combinations are possible. The bytes (111,45,0) create a color that looks like the color of my desk. The bytes (88,136,0) create a color that, to me, looks like it could be the color of grass.
For an image that is displayed on a computer screen, the individual points of light that make up the image are called pixels. Even a relative small image can contain many pixels that make up that image. Pixels are laid out in a square grid. So the number of pixels contained in an image can be calculated by multiplying the width and the height measured in pixels. A common size for a small icon is 32 × 32 pixels. Even for such a small image there are 1024 individual points of light. Everyone of these pixels requires at least 3 bytes, one for each of the primary colors of light. So an icon of this size requires at least 3 × 32 × 32 = 3072 bytes, which is about 3 kilobytes.
| RGB System | ____ A single point of light on a computer screen. |
| The primary colors of light. | ____ The absence of any light. |
| Black | ____ A way of representing colors by combining 3 main colors. |
| White | ____ Colors that can be combined to produce any visible color. |
| Pixel | ____ All primary colors of light at full intensity. |
| Combination | Result | Red (255,0,0) and Dark Green (0,128,0) | Dark Green (0,128,0) and Dark Blue (0,0,128) | Dark Red (128,0,0) and Dark Green (0,128,0) and Dark Blue (0,0,128) | Magenta (255,0,255) and Green (0,255,0) |
| HTML Color | Color Word | |