Chapter 2: Basic Computer Terminology
Introduction
As stated earlier, computers have added many new terms to the English language. More specifically, programming languages have also added many terms to the language or have added new definitions to their meanings. Before going into different programming languages, there are a few terms that must be understood that are common to most all computer languages. The programmer should realize that most of these terms are related to math in some form as computers are based solely on math, more specifically binary math.The Binary Number System
Computers are based solely on math. Due to how computers are produced, they can only really deal with two numbers, 0 and 1. This style of numbering is called the binary number system (in math terms it is considered base-two). An individual digit of a binary number is called a bit (a bit is the smallest number a computer can deal with). Before explaining binary, I'll explain how humans deal with numbers.Humans normally deal with the decimal number system (in math the decimal system is considered to be base-ten). The decimal number system has ten numbers in it, 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The way we use this numbering system is we look at the rightmost digit and count to the left. For instance, if there are 4 digits (1000 for example), then the number must be in the thousands and that number must be somewhere between 1,000 and 9,999. We were taught in elementary school that the rightmost digit is the ones position, the one to the left is the tens position, and so forth. What is actually happening is we are calculating higher powers of 10 (the base according to mathematicians) as we go to the left. If you're confused, just bare with me and let me explain and show you how this works.
The rightmost digit corresponds to 100 which is equal to 1 (any number to a zero power is equal to one [don't ask me why, just trust me and remember it J]). The digit to the left of that one is equal to 101 which equals 10. The next one is equal to 102 (10x10) which is equal to 100. The forth digit from the right is equal to 103 (10x10x10) which is 1,000. See Table 2 to see how the decimal system calculates one million.
1,000,000 | 100,000 | 10,000 | 1,000 | 100 | 10 | 1 | |||
106 | 105 | 104 | 103 | 102 | 101 | 100 | |||
1 | , 0 | 0 | 0 | , 0 | 0 | 0 |
Table 2 - Powers of 10
Notice that so far we have only calculated a number that has a one as the leftmost digit and all other digits are zero. This is basic to understanding how humans figure out what a number is. The next step is to show how we calculate any number.A simple formula is needed in order to calculate the value of any number of the decimal system. Since there are ten numbers in the decimal system and since the number modifies the value at its position (a 40 is not a 10, but is 4 times 10), we must find a way to find out what the actual value is at a specific position. All we have to do is multiply the digit at a certain position with its power and add all of these numbers together. For example, the number 423 is equal to 3*100 + 2*101 + 4*102 which is equal to 3*1 + 2*10 + 4*100 which is equal to 423 [of course]. Have I thoroughly confused you? Hope not. This process of breaking apart a number is actually considered to be converting a decimal number to a decimal number, which is useful as an example but nothing more. What we would like to do is see how the binary number system works in comparison to the decimal number system.
The binary number system is very similar to the decimal number system except that we use two to a certain power instead of ten. The formula is the same. It is useful to note that the formula will convert a binary number into a decimal number. Table 3 shows how a binary number is converted into a decimal number. Note how the binary number only has the digits 0 or 1, that's because that is all the binary number system contains.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | ||||
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | ||||
1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | ||||
11010010 in binary = 0*20 + 1*21 + 0*22 + 0*23 + 1*24 + 0*25 + 1*26 + 1*27 = 0 + 2 + 0 + 0 + 16 + 64 + 128 = 210 in decimal |
Table 3 - Binary to Decimal
Computers themselves use binary but programmers use decimal, octal (base-eight [contains only the numbers 0-7]), and hexadecimal (base-sixteen [contains the numbers 0-9 as well as the letters A-F]). It is not necessary that the programmer learn these other bases at this time but just be aware that they exist in the computer field (you'll see hexadecimal [short form is hex] soon).Types of Numbers
Humans have various terms to refer to certain types of numbers. For instance, we call ½ a fraction, and .4 a decimal, and –4 a negative number. For more complex math, we call 5i+3 a complex number. Computers have similar names for numbers. All of the following number types can be signed (allowing positive, zero, and negative numbers) or unsigned (allowing only zero or positive numbers). A special note is that on numbers above 999, a comma should not be included within the number.Integers
Integers are numbers without any decimal points. The number can be negative, zero, or positive. It must be a whole number and not contain a fraction. For example, 1000, 0, 25, 1, -4 are all integers but .1, .333, 5.2, 1.000001, and –99.99 are not integers. Integers are used in computers for speed as the computer does not have to deal with fractions. Some examples of how they are used in computers would be in the form of a date (1-1-2001) or time (12:00).
On most computers, integers are measured in how many bits (binary digits) they contain. On old computers, an integer contained only 8 bits. On modern computers, an integer contains anywhere between 32 and 128 bits [depends on the computer]. What this means is that a computer can only count but so high or low. An 8-bit number has a decimal range from 0 to 255 or –127 to 128 [if you're wondering how I'm getting the decimal ranges, 28=256 numbers. Zero must be included so the range is 0 to 255.]. A 16-bit number has a maximum range up to 65,536 numbers. A 32-bit number has an upper limit of 4,294,967,296! You may ask what happens when you try to go over this range, well, it depends. If the computer is allowed to use negative numbers as well as positive then if you add 1 to a number that has reached the maximum limit, you'll get a negative number on the lower limit of the range. On the other hand, if the computer is not allowed to use negative numbers but only positive ones and you add a 1 to a number already at its maximum, you'll get zero as the answer. Yes, this can cause problems. (ah, another problem for you to solve in the future J).
Byte
A byte is a smaller version of an integer. It is usually only 8-bits long. As stated earlier, it contains 256 numbers. Bytes are used mainly for characters that the computer can produce. I'll explain this at a later time. For now, just think of a byte as a smaller version of an integer. Believe it or not, it is usually faster to use integers instead of bytes for storing information! Yes, bytes are much smaller than integers, but the computer's basic unit is an integer. [It is similar to how an American's basic unit of money is the dollar but we have smaller units of money such as quarters and pennies].Single and Double Precision and Floats
Numbers that contain decimals are called, depending on the programming language, single/double precision or floats.The reason for the single and double precision difference is just the bit size and the number of digits that could be in the number. For example, a single precision number may store the fraction 1/3 as 0.33333 where a double precision will store it as 0.3333333333. Double precision does not necessarily mean that there will be double the amount of digits available for a number, this will depend on the language being used. Another note, single precision numbers can be calculated faster than double precision numbers, but both are much slower than integers.
Floats (named floats for the term floating point) are single or double precision numbers with just a different name. They are called floats because the decimal point can "float" anywhere within the number. I will refer to this group of numbers as floats throughout this book except when talking about certain languages.
This group of numbers is useful for calculating formulas that contain fractions. For example, to calculate how much tax would be added to an item would require a float.
Longs
Longs are basically integers that have a larger range than a normal integer. Longs are useful when an integer is just too small.Other Types
Computers can deal with other types of information as well as numbers. To be truthful, even these types are numbers but they are in a special classification because of the way humans perceive them. For instance, if a statement is true, a human probably wouldn't say that a statement was –1. In Qbasic this is what the computer would say to a true statement! For example, the formula 2+2=4. A human would say, yes, 2+2 does equal 4. In Qbasic, the computer would say 2+2=4 equals –1!Boolean
Boolean types deal with a section of mathematics called Boolean logic. To put this in simple terms, it deals with whether a statement is true or false. The computer has no idea what true means or what false means but uses Boolean logic to figure out the truth of a statement. In most programming languages, 1 means true and 0 means false (Qbasic uses –1 to mean true and 0 to mean false).Character
A character is almost always the same thing as a byte. A character can be any single letter, number, or symbol that is on the keyboard, among others symbols that the computer can produce. A character is actually the symbol itself (such as an 'A' or space). Internally the computer represents each symbol as a number. For instance, the character 'A' is internally represented as the number 65 and a space as number 32. Where does the computer get these numbers from for the characters?Around 1968, a group of computer scientists came up with a table that contains all of the symbols the computer can normally produce and assigned a number to each of them. This table is called the ASCII table
[American Standard Code for Information Interchange]. This table contains 256 individual characters. The first half of the ASCII table is standard for all modern day personal computers. Figure 1 shows the entire IBM PC version of the ASCII table.
Figure 1 – Hex IBM PC ASCII Table
In the programming language Java, the ASCII table is being replaced with a table called Unicode. The Unicode table contains the ASCII table as well as many more symbols. It uses a 16-bit byte value and thus has a total capacity of 65,536 symbols.
No comments:
Post a Comment