Byte Manipulation
The most common use of bit manipulations is for packing and unpacking “bytes” consisting of several bits from words each of which contain several bytes. This can lead to major savings in space. If an exam score lies always between 0 and 100, only seven bits are required to hold each score, since (27-1) is 127. Another way to see this is to write the largest 7-bit quantity: 11111112 = 1778 = 1×82+7×81+7×80 = 64+56+7 = 127. This is one less than 2008, which requires an eighth bit. We can fit eight 7-bit bytes into each 60-bit word. Happily, TUTOR will do the bookkeeping, as we saw earlier:
define segment,scores=n31,7
This definition makes it possible to work with this “segmented” array as though it were an ordinary array:
These refer to the 3rd and 17th bytes. The first eight 7-bit bytes reside in n31, with the last 4 bits unused. The next eight bytes are in n32, etc. The 17th byte is the first 7-bit byte in n33.
Just as it is possible to give up one bit of a 60-bit word in order to have negative as well as positive numbers, so it is possible to have both positive and negative numbers stored in a segment array:
With 8-bit bytes we can have numbers in the range of ±127. The word “signed” may be abbreviated by “s”.
Now that you understand the bit structure of a variable, you should be able to understand the table (Table 10-1) provided earlier of segment ranges and the number of segments per variable. Look at the table now and see whether you can check the entries in the table.