Fundamental Data Types |
|
|
Boolean Variables |
The Boolean data type uses 8 bits to store a variable whose value would be set as true (1) or false (0). To declare such a value, you use the Boolean keyword. Here is an example var IsMarried: Boolean; |
Short Integers |
An algebraic natural number is also called an integer. A byte can be used to store a natural number provided it uses a small value. The data type used to declare such a variable is Shortint. The value stored in a Shortint variable must range from –128 to 127. The variable can be declared as follows: var BookLength: Shortint; If the values of the variable must be unsigned, you can declare it using the Byte keyword. In this case, the values of the variable must range between 0 and 255. Here is an example of declaring such a variable: var MemberAge: Byte; |
A Word |
Representing a Word |
A Word is a group of 16 consecutive bits. The bits are counted from right to left starting at 0: |
Considered as a group of 16 bits, the most right bit of a word, bit 0, is called the least significant bit, or Low Order bit, or LO bit, or LOBIT. The most left bit, bit 15, is called the most significant bit, or High Order bit, or HI bit, or HIBIT. The other bits are referred to using their positions: bit 1, bit 2, bit 3, etc. |
Wide Characters |
Object Pascal provides a data type to represent Unicode or international characters. These characters are represented using 16-bits. The data type to do this is called WideChar. |
Small Integers |
A word, which is a group of 16 contiguous bits or 2 bytes is used to represent a natural number that uses twice the space of a short integer. As we have studied, the maximum numeric value that can fit in a word is 65535. Based on this, a word can store a variable declared with the Smallint keyword. Here is an example: var WholeDistance: Smallint; A variable declared as Smallint can store a number between –32768 and 32767. If the number must be unsigned, you can declare it using the Word data type. In this case, the number must range from 0 to 65535. |
A Double-Word |
Representing a Double-Word |
A double-word is a group of two consecutive Words. This means that a double-word combines 4 bytes or 32 bits. The bits, counted from right to left, start at 0 and end at 31. |
The most right bit, bit 0, is called the Low Order bit or LO bit or LOBIT. The most left bit, bit 31, is called the High Order bit or HI bit or
HIBIT. The other bits are called using their positions. |
The minimum binary number you can represent with a double-word is 0x |
Integers |
A double-word provides twice the amount of space of a word. This is equivalent to 32 bits or 4 bytes or 4294967295. Therefore, a double-word is used for large numbers that would not fit in a word. If your program needs an integer variable whose value requires more memory space than a word can hold, declare it using the Integer keyword. The integer data type is used for a variable whose value can range from –2,1474,83,648 to 2,147,484,647. var AgeRange: Integer; Alternatively, you can use the Longint keyword to declare a variable whose value must be able to fit in a 32-bit space. If the variable must be positive, you can declared it using the Cardinal keyword. A Cardinal variable is used for a 32-bit positive integer whose value would range from 0 to 2,147,484,647. Here is an example: var ColonyPopulation: Cardinal; Besides Cardinal, to declare an unsigned natural variable, you can use the
Longword keyword. |
The other integer data types available in object Pascal are:
|
Floating-Point Numbers |
Floating-Point Variables |
The integers we have used so far have the main limitation of not allowing decimal places in their values. Object Pascal provides floating data types that would solve this problem. The most fundamental floating variable is declared with the Single keyword. A Single variable occupies 4 bytes of space and therefore can store a number that ranges from 1.5 x 10–45 and 3.4 x 10+38. To declare such a floating-point variable, use the Single keyword followed by the name of the variable. Here are examples: var Age: Single; When a variable is larger than the Single data type can handle and requires more precision, you should declare it using the Double keyword. The double-precision type is an 8 Byte decimal or fractional number ranging from 5.0 x 10–324 and 1.7 x 10308. |
Strings Fundamentals |
A string is an empty spave or a group of characters that form an entity or common value. To declare a string as a variable, you can use the string data type. Here is an example: var FirstName: string; Object Pascal also provides the AnsiString data type to declare a string variable. Its variable can be declared as follows: var FirstName: AnsiString; In most cases, when you declare a variable as string, Object Pascal implemented by Borland Delphi considers the variable as AnsiString. Such a variable can store characters or text to fit in 4 bytes to 2GB of space. |
|
||
Previous | Copyright © 2004 FunctionX | Next |
|