(Preliminary)
Follow these fast links:
The Char data type is used for individual 8-bit codes, many of which are used to represent printable characters. Each Char requires one byte of memory and can have a value from 0 to 255 (or 0 to 11111111 in binary). This data type, along with Integer and Boolean, belongs to the class of data types known as ordinals. An ordinal is one of a set of values, each of which has both a predecessor and a successor except for the first and the last. In Pascal, a Char literal is delimited by single quotes, e.g., 'C'.
A String can be viewed as an array of Chars.
Many different encoding schemes have been used to represent characters on computers. Below are two of the most widely used, ASCII and EBCDIC.
The original American Standard Code for Information Interchange (ASCII) used only 7 of the bits, with values from 010 to 12710 or 016 to 7F16. The first 32 codes and the last one are for controling communication and peripherals. The other 95 codes are for printable characters. They were intended to handle English only and they do not even do that well. Note that the hexadecimal value for a character is composed of the column value as the high-order digit and the row value as the low-order digit, e.g., the value for lowercase 'a' is 6116. The space character is 2016. Click here to see what the control code mnemonics for the codes 0016 to 1F16 stand for.
| ASCII CHART | ||||||||
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
| 0 | NUL | DLE | 0 | @ | P | ` | p | |
| 1 | SOH | DC1 | ! | 1 | A | Q | a | q |
| 2 | STX | DC2 | " | 2 | B | R | b | r |
| 3 | ETX | DC3 | # | 3 | C | S | c | s |
| 4 | EOT | DC4 | $ | 4 | D | T | d | t |
| 5 | ENQ | NAK | % | 5 | E | U | e | u |
| 6 | ACK | SYN | & | 6 | F | V | f | v |
| 7 | BEL | ETB | ' | 7 | G | W | g | w |
| 8 | BS | CAN | ( | 8 | H | X | h | x |
| 9 | HT | EM | ) | 9 | I | Y | i | y |
| A | LF | SUB | * | : | J | Z | j | z |
| B | VT | ESC | + | ; | K | [ | k | { |
| C | FF | FS | , | < | L | \ | l | | |
| D | CR | GS | - | = | M | ] | m | } |
| E | SO | RS | . | > | N | ^ | n | ~ |
| F | SI | US | / | ? | O | _ | o | DEL |
An earlier, but now rarely used, encoding system was the Extended Binary Coded Decimal Interchange Code (EBCDIC), which was used on IBM mainframes. It reflected the system of holes used on punch cards. It has fallen into disfavor partially because of the use of nonsequential codes for the alphabetic characters. Note that the hexadecimal value for a character is composed of the row value as the high-order digit and the column value as the low-order digit, e.g., the value for lowercase 'a' is 8116. The space character is 4016. The nonindented sections of the table indicate unused codes. Click here to see what the control code mnemonics for the codes 0016 to 3F16 stand for.
| EBCDIC CHART | ||||||||||||||||
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
| 0 | NUL | SOH | STX | ETX | PF | HT | LC | DEL | SMM | VT | FF | CR | SO | SI | ||
| 1 | DLE | DC1 | DC2 | DC3 | RES | NL | BS | IL | CAN | EM | CC | IFS | IGS | IRS | IUS | |
| 2 | DS | SOS | FS | BYP | LF | ETB | ESC | SM | ENQ | ACK | BEL | |||||
| 3 | SYN | PN | RS | UC | EOT | DC4 | NAK | SUB | ||||||||
| 4 | ¢ | . | < | ( | + | | | ||||||||||
| 5 | & | ! | $ | * | ) | ; | ¬ | |||||||||
| 6 | - | / | ^ | , | % | _ | > | ? | ||||||||
| 7 | : | # | @ | ' | = | " | ||||||||||
| 8 | a | b | c | d | e | f | g | h | i | |||||||
| 9 | j | k | l | m | n | o | p | q | r | |||||||
| A | s | t | u | v | w | x | y | z | ||||||||
| B | ||||||||||||||||
| C | { | A | B | C | D | E | F | G | H | I | ||||||
| D | } | J | K | L | M | N | O | P | Q | R | ||||||
| E | \ | S | T | U | V | W | X | Y | Z | |||||||
| F | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ||||||
A variable of the Boolean type can have only two values, TRUE and FALSE. A good compiler, therefore, can use a single bit for a boolean variable, packing up to eight such variables into a single byte of memory. Zero (0) is used to represent FALSE and one (1) is used for TRUE.
A boolean is one of the ordinal types. Internally, FALSE is treated like 0 and TRUE like 1. So TRUE is the successor of FALSE and FALSE is the predecessor of TRUE.
The result of an evaluation of a Boolean expression can be assigned to a Boolean variable, e.g.,
boo : Boolean; boo := 5 < 4; writeln(boo);
will result in the word FALSE being printed.
Booleans are typically used as flags to store what a current condition is. This can be seen in a reworking of the program on the User-Controlled Repetition with the Repeat-Until Loop page.
QuitProgram : boolean; {Loop control variable}
Repeat
.
.
.
{-------------------User Control------------------}
write('Do you want to do another? (Y/N) ');
readln(response);
if (upcase(response) = 'N') then
QuitProgram := TRUE
Until QuitProgram
An Integer is a two-byte ordinal data type. The range possible is from -32768 to 32767. The largest value is assigned to the Pascal constant MaxInt. In the binary representation, the highest-order bit of the 16-bit value is known as the sign bit -- if it is a one (1), the value is negative.
A error which frequently occurs in programming is the choice of a data type which is too small to hold a particular value. Consider the following code, for example.
x : Integer; x := MaxInt; x := x + 1; writeln(x)
This code will print the value -32768. This is known as overflow. Examine the following table.
| Integer Range of Values | ||
| Smallest Value | Largest Value | |
| Decimal | -32768 | 32767 |
| Binary | 1000 0000 0000 0000 | 0111 1111 1111 1111 |
| Hexadecimal | 8000 | 7FFF |
The following binary addition demonstrates how the value stored in x became negative.
0111 1111 1111 1111
+1
--------------------
1000 0000 0000 0000
The result of the addition is negative, as can be seen by the highest-order bit being a 1. The resultant value is the binary representation of the smallest value that can be stored in an Integer variable.
An LongInt is a four-byte ordinal data type, making it twice as long as an Integer in terms of bits. The range possible is from -2147483648 to 2147483647. The largest value is assigned to the Pascal constant MaxLongInt. In the binary representation, the highest-order bit of the 32-bit value is known as the sign bit -- if it is a one (1), the value is negative.
x : LongInt; x := MaxLongInt; x := x + 1; writeln(x)
This code will print the value -2147483648. This is known as overflow. The following table shows the smallest and largest values in decimal, binary and hexadecimal that can be stored in a LongInt.
| LongInt Range of Values | ||
| Smallest Value | Largest Value | |
| Decimal | -2147483648 | 2147483647 |
| Binary | 1000 0000 0000 0000 0000 0000 0000 0000 | 0111 1111 1111 1111 1111 1111 1111 1111 |
| Hexadecimal | 80000000 | 7FFFFFFF |
A Real is a six-byte non-ordinal data type. This means that it cannot be used as the loop control variable in a for-to-do loop.
The range of a positive Real variable is from 2.9 x 10-39 to 1.7 x 1038; approximately the same holds for negative values. A Real maintains about 11 significant digits.
Consider the following code fragment:
x : Real; x := 13.2; writeln(x);
This will result in 1.3200000000E+01 being printed. This is know as E-notation and is equivalent to 1.32 x 101 in scientific notation.
Since normal people find reading such notation bothersome, Pascal allows you to specify the number of decimal places to be used in the output. For example, the following
writeln(x:1:2)
would print 13.20 as output. The value after the first colon specifies the field width and the second specifies the number of decimal places to be used. If the first value is less than the total length of the string being printed, the string is printed quad left (left justified); if the first value is more than the total length, the string is printed quad right (right justified) within the field. Thus, decimal values such as those used for money can be made to line up:
x : Real; y : Real; x := 13.2; y := 11; writeln(x:7:2); writeln(y:7:2);
would result in the following output, where the carets are used to indicate wordspaces.
^^13.20 ^^11.00
| ASCII CONTROL CODES | |||||
00| NUL | NULl | 10 | DLE | Data Link Escape
| |
| 01 | SOH | Start Of Heading | 11 | DC1 | Device Control 1 |
| 02 | STX | end of heading or Start of TeXt | 12 | DC2 | Device Control 2 |
| 03 | ETX | End of TeXt | 13 | DC3 | Device Control 3 |
| 04 | EOT | End Of Transmission | 14 | DC4 | Device Control 4 |
| 05 | ENQ | ENQuiry (to request identification) | 15 | NAK | Negative AcKnowledge |
| 06 | ACK | ACKnowledge | 16 | SYN | SYNchronouos idle |
| 07 | BEL | ring BELl | 17 | ETB | End of Transmission Block |
| 08 | BS | BackSpace | 18 | CAN | CANcel previous transmission |
| 09 | HT | Horizontal Tab | 19 | EM | End of Medium |
| 0A | LF | Line Feed | 1A | SUB | SUBstitute a character for another |
| 0B | VT | Vertical Tab | 1B | ESC | ESCape |
| 0C | FF | Form Feed | 1C | FS | File Separator |
| 0D | CR | Carriage Return | 1D | GS | Group Separator |
| 0E | SO | Shift Out (begin non-ASCII bit string) | 1E | RS | Record Separator |
0F| SI | Shift In (end non-ASCII bit string) | 1F | US | Unit Separator | |
| EBCDIC CONTROL CODES | |||||||||||
| 00 | NUL | NULl | 10 | DLE | Data Link Escape | 20 | DS | Digit Select | 30 | ||
| 01 | SOH | Start Of Heading | 11 | DC1 | Device Control 1 | 21 | SOS | Start Of Significance | 31 | ||
| 02 | STX | end of heading or Start of TeXt | 12 | DC2 | Device Control 2 | 22 | FS | File Separator | 32 | SYN | SYNchronous idle |
| 03 | ETX | End of TeXt | 13 | DC3 | Device Control 3 | 23 | 33 | ||||
| 04 | PF | Punch ofF | 14 | RES | REStore | 24 | BYP | BYPass | 34 | PN | Punch oN |
| 05 | HT | Horizontal Tab | 15 | NL | NewLine | 25 | LF | Line Feed | 35 | RS | Record Separator |
| 06 | LC | Lower Case | 16 | BS | BackSpace | 26 | ETB | End of Transmission Block | 36 | UC | Upper Case |
| 07 | DEL | DELete | 17 | IL | IdLe | 27 | ESC | ESCape | 37 | EOT | End Of Transmission |
| 08 | 18 | CAN | CANcel previous transmission | 28 | 38 | ||||||
| 09 | 19 | EM | End of Medium | 29 | 39 | ||||||
| 0A | SMM | repeat | 1A | CC | unit backspace | 2A | SM | Start Message | 3A | ||
| 0B | VT | Vertical Tab | 1B | 2B | 3B | ||||||
| 0C | FF | Form Feed | 1C | IFS | Interchange File Separator | 2C | 3C | DC4 | Device Control 4 | ||
| 0D | CR | Carriage Return | 1D | IGS | Interchange Group Separator | 2D | ENQ | ENQuiry (to request identification) | 3D | NAK | Negative AcKnowledge |
| 0E | SO | Shift Out (begin non-EBCDIC bit string) | 1E | IRS | Interchange Record Separator | 2E | ACK | ACKnowledge | 3E | ||
0F| SI | Shift In (end non-EBCDIC bit string) | 1F | IUS | Interchange Unit Separator | 2F | BEL | ring BELl | 3F | SUB | SUBstitute a character for another | |