All data in a computer is represented in binary. The pictures of your summer vacation stored on your hard drive—it’s all bits. The YouTube video of the cat falling off the chair that you saw this morning—bits. Your Facebook page—bits. The tweet you sent—bits. The email from your professor telling you to spend less time on vacation, browsing YouTube, updating your Facebook page and sending tweets—that’s bits too. Everything is bits.
A file on a computer is simply a sequence of bytes, nothing more, nothing less. What imbues the file with meaning is how we (or a program) choose to interpret those bytes. This is actually the same with language. The string bow has no intrinsic meaning. It's up to us to decide whether it means something you shoot with, put in a little girl's hair, or whether it means bending over in a polite manner.
This page is a review of prior courses (SY110 - Cyber 1) and will cover the basics of information representation, binary and hexadecimal number systems, converting between different number systems, and representation of characters. At the bottom of the page are some practice problems and external video resources.
The order of the digits matters. There is a big difference between 821 and 128. The digit that makes the largest impact is the one farthest to the left. This is the most significant digit as it is multiplied by 10 raised to the largest power. The digit all the way to the right is the least significant as it is only multiplied to 10 raised to 0 or just by 1.
We humans think about numbers using the decimal number system because we have ten fingers. For instance, a decimal number can be represented as a sum of powers of 10 (referred to as base-10 system).
The values available for each digit in a base 10 system are 0 to 9. Each digit represents a power of the base, in this case 10. The first position is the digit value times the base (10) raised to the power of zero.
To convert decimal numbers to binary, recall how you first learned to divide integers in elementary school. If you recall, when you divided one integer value by another, the result was a quotient and a remainder. For example, 7 ÷ 4 = 1, with a remainder 3. Here, the quotient is 1, and the remainder is 3. We’ll use this to do the decimal-to-binary conversion as follows. Since we’re converting the value to binary (base 2), we will divide the decimal value by 2. To convert decimal value x to binary:
• Divide x by 2, calculate the quotient (call it q) and note the remainder (the remainders will always be 0 or 1)
• Divide that quotient (q) by 2, calculate the new quotient and note the remainder
• Continue dividing the resulting quotients by 2, and each time noting the remainder, until the quotient = 0 at which point you stop
• The binary conversion then is the remainder terms in reverse order.
For computers, we can abstract their information representation to the lowest possible set of values. This is called binary representation and is a base 2 system, with each digit being either 0 or 1. Each position is multiplied by the base (in this case 2) raised to that positions' power just as in the base 10 system. Since there are only 2 digits (0 and 1) we have to add positions to our binary number more frequently. Counting in binary is shown on to the left
We need to be able to readily shift between the binary and decimal number representations. To convert a binary number to a decimal number, we simply write the binary number as a sum of powers of 2 (binary numbers are a base-2 system).
Convert 106 decimal to binary:
We need to be able to readily shift between the binary, hexadecimal, and decimal number representations. To convert a hexadecimal number to a decimal number, we simply write the number as a sum of powers of 16.
You can also convert each individual hex digit to binary, then convert that value to decimal.
We can convert directly from hexadecimal notation to the equivalent binary representation by using the following procedure:
• Convert each hexadecimal digit to a four digit binary number, independent of the other hexadecimal digits.
• Concatenate the resulting four-bit binary numbers together.
Shown below is the conversion for each single hex digit to 4-bit binary and then to decimal:
We often have to deal with large positive binary numbers. For instance, consider that computers connect to the Internet using a Network Interface Card (NIC). Every NIC in the world is assigned a unique 48-bit identifier as an Ethernet address. You would probably agree that these long binary strings are cumbersome to transcribe or to read off to a coworker. Even if you have come to love the binary number system, you would still likely agree that these long strings are impractical.
Fortunately, large binary numbers can be made much more compact—and hence easier to work with—if represented in base-16, the so-called hexadecimal number system. You may wonder: binary numbers would also be more compact if represented in base-10—why not just convert them to decimal? The answer, as you will soon see, is that converting between binary and hexadecimal is exceedingly easy—much easier than converting between binary and decimal.
The Hexadecimal (Base-16) Number System has 16 digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Note that the single hexadecimal symbol A represents the decimal number 10, B represents 11, and so on, up to F, which represents 15. Just as with decimal notation or binary notation, we again write a number as a string of symbols, but now each symbol is one of the 16 possible hexadecimal digits (0 through F). To interpret a hexadecimal number, we multiply each digit by the power of 16 associated with that digit’s position.
To convert a decimal number to hexadecimal, you use an approach similar to that used in converting a decimal number to binary. The difference here is that since we’re converting to hexadecimal (base 16), we will be dividing by 16, and the remainder values will be hex values, 0-9 or A-F.
Within a computer, positive integers are stored in four bytes by converting the integer to a binary number. We now address the representation of characters, such as letters of the alphabet, punctuation signs and other assorted symbols (e.g., $, %, etc.).
Characters are stored within the computer using the American Standard Code for Information Interchange code—the ASCII code—shown in the table below. Each ASCII symbol is shown with both its hexadecimal representation and its base-10 representation. Suppose we wanted to know how the symbol for the question mark is stored internally within the computer. Scanning the table for the question mark, we locate it at the bottom of the second column, and we note that its hexadecimal value is 0x3F. Converting this hexadecimal value to binary, we conclude that the question mark is stored as 001111112.
Crash Course
Computerphile