| |
Like integers, words are 16-bit (2-byte) memory objects. Unlike integers, which can
be either positive and negative, variables of type word are always positive and are used in situations where negative
values aren't needed or where a variable represents a bit pattern rather than a value. The value of a word can
range from 0 to 65535.
Pascal provides numerous operators for manipulating words. Most have a direct expression in machine language and
are therefore performed very quickly.
The AND, OR, and XOR operators take 2-word operands and produce a word result by performing
the appropriate Boolean operation on each of the 16 bit pairs. For example, where A and B are words:
A = $5555 = 0101010101010101 binary
B = $00EF = 0000000001111111 binary
A AND B = set bits that are on in both A and B = 0000000001010101
A OR B = set bits that are on in either A or B = 0101010101111111
A XOR B = set bits that are different in A and B = 0101010100101010
The NOT operator complements (flips each bit) of its word operand:
NOT B = 1111111110000000 binary
The SHL/SHR (shift left/shift right) operators slide the bits in a word to the right or left, shifting
in zeros as necessary.
A SHL 2 = 0101010101010100 binary
B SHR 5 = 0000000000000011 binary
The Hi and Lo functions return the high- and low-order bytes, respectively of their word parameters:
Hi(B) = 00000000 binary
Lo(B) = 01111111 binary
The Swap function reverses the high- and low-order bytes of its word parameter and returns this value:
Swap(B) = 0111111100000000 binary |