This is the second installation of a series of programming sessions. Information presented in this session are taken from a variety of sources, including the authors experiences in programming computers over several years.
In the last Session, we covered
Data Type refers to a structured system of determining what type of data the internal binary data represents.
image removed
The most basic PC architecture consists of the Central Processing Unit (CPU), Data Bus, Address Bus, RAM, Storage Devices and IO. These devices are the bare minimum requirements for a computer.
A computer is a box of switches. They are either on or off (represented by voltages inside the circuitry). To make them useful, eight of these 'switches' are combined into a bus with eight lines (one for each switch).
The CPU will read and write to and from the RAM, Storage and IO devices as the program it runs is executed. The RAM is addressed a bit like a pigeon hole system, each location is a unique address, similar to a street address to locate your house or business from anywhere in the world.
Also known as base 10, this system is in use throughout the majority of our daily lives, from the number of fingers on our hands, money and measurement systems (especially metric)
The computer can't work easily with decimals the way we do. Since the underlying electronic circuitry is actually a bunch of switches (albeit solid state), this system is the one we need to understand when we are dealing with a computer.
Derived from Binary and used in the early days of programming to simplify the human computer interface, this system turns 3 binary digits into a single digit.
As computers became more complex and increased the sizes of their buses, this system has come to replace binary and octal for human readability, by combining 4 binary digits into a single hex digit.
It turns out that the binary system could be used to represent almost anything we want, but without a strict way of stating that the block of memory holds a collection of characters (strings) or a series of numbers (like lotto numbers), then we have no way of really determining the meaning of the data.
Smallest binary item, called a bit (binary digit). Has two states, either electrically high or low representing the states On or Off, True or False
Consists of four Bits, which can used to represent 16 possible combinations from 00002 to 11112. Some calculations within the CPU use the boundary between two nibbles to indicate an overflow in BCD (binary coded decimal) computations
Eight bits or two nibbles, there are now 256 (162) combinations, more than ample to represent upper and lower case letters (char).
Generally consists of 2 bytes or 16 bits, giving 65536 combinations in the bit pattern.
4 bytes, 32 bits. The current PC architecture is at this level, with the ability to represent 4294967296 combinations.
Also known as Data Structures, Representations or Types, these structures are used by the programmer, then the program complier to determine what format to store information.
Normally, we are not concerned with internal structure, only with its minimums and maximums. The programmer has a responsibility to ensure the format used today will be useful for a reasonable period before 'beefing up' the program in the future.
Earlier programs were very concerned with memory and storage constraints, so programmers sometimes resorted to a 'custom' format to suit their needs when the standard types failed to deliver the required functionality.
The most basic type of format is the 'Unsigned Byte'. The full eight bits represent (in binary) numbers from 0 to 255. Had this 'Unsigned Byte' been nominated as Char, then the ASCII (or ANSI) table should be consulted to see the assigned meaning of each byte. As we increase the number of bits, the range of unsigned values is from 0 to 2n, where n is the number of bits, ie if there are 10 bits then the minimum unsigned value is 0 and the maximum is 210 or 1024.
The 'Signed Byte' uses one bit to represent 'Plus' or 'Minus', and the remaining 7 bits to identify the number. The range of values is from -128 to +127. The 'Signed' integers have a minimum value starting at -1 * (2n-1) up to (2n-1)-1. So a 4 byte (32 bit) signed integer has minimum value of -1 *(232-1) or -2147483648, and a maximum value of (232-1)-1 or +2147483647.
Like the integers, the reals have size and signs to make them meaningful. Their minimums and maximums are directly related to the number of bits, and they have the additional mathematical constraint on the number of significant digits when they are used. They are also known as 'Floating Point' numbers.
Summarised for the Real or Floating Point types defined for Borland Turbo Pascal:
| Type | Range (- and +) | Significant
Digits |
Size
(Bytes) | |
| Min | Max | |||
| Real | 2.9 x 10-39 | 1.7 x 1038 | 11-12 | 6 |
| Single | 1.5 x 10-45 | 3.4 x 1038 | 7-8 | 4 |
| Double | 5.0 x 10-324 | 1.7 x 10308 | 15-16 | 8 |
| Extended | 3.4 x 10-4932 | 1.1 x 104932 | 19-20 | 10 |
| Comp | -263+1 | 263-1 | 19-20 | 8 |
The numbers that can be represented are staggeringly large and infinitely small. Selecting the correct one can make or break a calculation in scientific and mathematic circles. Suffice to say, if and when you decide to make you way into programming, read the language references before selecting a data type.
These are probably the simplest to comprehend. There are some areas where characters require the use of two bytes (such as the Japanese Katakana set). In the case of compiler specifics, C/C++ strings simply end with a byte containing the binary number 0, while Pascal uses a structure which has the exact number of bytes followed by the string of characters in successive memory locations.
We have now covered sufficient material to further our lessons on Programming. In the next session, we will begin to cover language specific areas, beginning with Pascal.
Appendix ASCII Table Reference: Borland Turbo Pascal for Windows Programmers Guide Table B.1 Pages 414-415.
images removed