Fundamental Data Types

 

A Byte

 

Representing a Byte

Byte

A byte is a group or eight consecutive bits. The bits are counted from right to left starting at 0. The most right bit is bit 0; it is called the least significant bit. It is also referred to as the Low Order bit, the LO bit, or LOBIT. The most left bit is bit 7; it is called the most significant bit, the High Order bit, the HI bit, or HIBIT. The other bits are referred to by their positions.

A byte is considered as being made of two nibbles:
Byte

Using the binary system, you can represent the byte using a combination of 0s and 1s. When all bits have a value of 0, the byte is represented as 00000000. On the other hand, when all bits have a value of 1, the byte is represented as 11111111. When the number grows very large, it becomes difficult to read. Therefore, we will represent bits in groups of four. Instead of writing 00000000, we will write 0000 0000. This makes the number easier to read.

If you have the patience to create combinations of bits using the boxes as we did for the nibble, you would find out that there are 256 possible combinations. Another way to find it out is by using the base 2 technique:

27 + 26 + 25 + 24 + 23 + 22 + 21 + 20
= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 255

Therefore, the maximum decimal value you can store in a byte is 255.

Remember that the byte with all bits having a value of 0 has its value set to 0. Since this byte also holds a valid value, the number of combinations = 255 + 1 = 256.

When a byte is completely represented with 0s, it provides the minimum value it can hold; this is 0000 0000, which is also 0. When all bits have a value of 1, which is 1111 1111, a byte holds its maximum value that we calculated as 255 in the decimal system. As done with the nibble, we get the following table:

  Decimal Hexadecimal Binary
Minimum 0 0x0 0000
Maximum 255 0xff 1111 1111

The minimum storage area offered by the (Intel) computer is the byte. As you know already, a byte is a group of 8 consecutive bits. The amount of memory space offered by a byte can be used to store just a single symbol, such as those you see on your keyboard. These symbols, also called characters, have been organized by the American Standard Code for Information Exchange (ASCII) in a set list. But, ASCII uses only 128 decimal numbers (based on a 7-bit format) to represent symbols counted from 0 to 127. To compensate for the remaining 1 bit, IBM used it to organize special characters, foreign language characters, mathematical symbols, small graphics, etc. Each one of these characters has a decimal, a hexadecimal, and a binary equivalents.

Character Variables

A byte is used to hold a single character. A character is an individual symbol that displays on your screen. It could be:

  • A lowercase letter: a, b, c, d, e, f, g, h, I, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, and z
  • An uppercase letter: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, And Z
  • A digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9
  • A special character: ` ~ # $ ! @ % ^ & * ( { [ ) } ] | \ : ; “ ‘ + - < _ ? > , / =.

To declare a variable as a character, you can use the Char or the AnsiChar keywords. Here is an example:

var MiddleInitial: Char;:

 

 

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:

 
Word
 

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.

Considering that a word is made of two bytes, the group of the right 8 bits is called the least significant byte, or Low Order byte, or LO byte, or LOBYTE. The other group is called the most significant byte, or High Order byte, or HI byte, or HIBYTE.

Word

The most fundamental representation of a word in binary format is 0000000000000000. To make it easier to read, you can group bits in 4, like this: 0000 0000 0000 0000. Therefore, the minimum binary value represented by a word is 0000 0000 0000 0000. The maximum binary value represented by a word is 1111 1111 1111 1111.

The minimum decimal value of a word is 0. To find out the maximum decimal value of a word, you can use the base 2 formula, filling out each bit with 1:

1*215 + 1*214 + 1*213 + 1*212 + 1*211 + 1*210 + 1*29 + 1*28 + 1*27 + 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20

= 32768 + 16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1

= 65535

The minimum hexadecimal value you can store in a word is 0x0000000000000000. This is also represented as 0x00000000, or 0x0000, or 0x0. All these numbers produce the same value, which is 0x0. To find out the maximum hexadecimal number you can store in a word, replace every group of 4 bits with an f or F:

1111 1111 1111 1111
f f f f
= 0xffff
= 0xFFFF
= 0Xffff
= 0XFFFF

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.

Double Word

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 group of the first 8 bits (from bit 0 to bit 7), which is the right byte, is called the Low Order Byte, or LO Byte. It is sometimes referred to as LOBYTE. The group of the last 8 bits (from bit 24 to bit 31), which is the left byte, is called the High Order Byte, or HI Byte or HIBYTE. The other bytes are called by their positions.

The group of the right 16 bits, or the right Word, is called the Low Order Word, or LO Word, or LOWORD. The group of the left 16 bits, or the left Word, is called the High Order Word, or HI Word, or HIWORD.

Double Word

The minimum binary number you can represent with a double-word is 0x

The minimum decimal value of a double-word is 0. To find out the maximum decimal value of a word, you can use the base 2 formula giving a 1 value to each bit:

2n-1 230 229 228 227 226 225 224
etc 1,073,741,824 536,870,912 268,435,456 134,217,728 67,108,864 33,554,432 16,777,216

223 222 221 220 219 218 217 216
8,388,608 4,194,304 2,097,152 1,048,576 524,288 262,144 131,072 65,536

215 214 213 212 211 210 29 28
32,768 16,384 8,192 4,096 2,048 1,024 512 256

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

1*231+1*230+1*229 + 1*228 + 1*227 + 1*226 + 1*225 + 1*224 + 1*223 + 1*222 + 1*221 + 1*220 + 1*219 + 1*218 + 1*217 + 1*216 + 1*215 + 1*214 + 1*213 + 1*212 + 1*211 + 1*210 + 1*29 + 1*28 + 1*27 + 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20 

= 2,147,483,648 + 1,073,741,824 + 536,870,912 + 268,435,456 + 134,217,728 + 67,108,864 + 33,554,432 + 16,777,216 + 8,388,608 + 4,194,304 + 2,097,152 + 1,048,576 + 524,288 + 262,144 + 131,072 + 65,536 + 32,768 + 16,384 + 8,192 + 4,096 + 2,048 + 1,024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 

= 4,286,578,708 

The minimum hexadecimal value you can store in a word is 0x0. To find out the maximum hexadecimal number you can represent with a word, replace every group of 4-bits with an f or F:

1111 1111 1111 1111 1111 1111 1111 1111
F F F F F F F F
= 0xffffffff = 0XFFFFFFFF = 0xFFFFFFFF

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.

Here is an example:

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.

If you want to use a natural number whose value is very large, you can use the Int64 keyword to declare it.

The other integer data types available in object Pascal are:

Type Minimum Maximum Format
Integer –2147483648 2147483647  signed 32-bit
Cardinal 0 4294967295  unsigned 32-bit
Shortint –128 127 signed 8-bit
Smallint –32768 32767 signed 16-bit
Longint –2147483648 2147483647 signed 32-bit
Int64 –2^63 2^63–1 signed 64-bit
Byte 0 255 unsigned 8-bit
Word 0 65535 unsigned 16-bit
Longword 0 4294967295 unsigned 32-bit

 

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.

For an even larger variable, use the 10 bytes real data type call Extended. An Extended variable can store a number that ranges from 3.4 x 10-4932 to 1.1 x 104932.

Object Pascal also provides the Real48 data type used to declare a flowing pointer variable. It can store a value between 2.9 x 10–39 and 1.7 x 1038. Alternatively, to declare a variable that represents a monetary value, you can use the Currency data type. It can be used to a store a number between –922337203685477.5808 and 922337203685477.5807. Previous versions of Object Pascal were also using the Comp data type that would be used to store numbers that range between –263+1 and 263 –1.

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