Octal and Hexadecimal Data Types

Octal and hexadecimal data types are integer types that are available in most computer languages. They provide a convenient notation for the construction of integer values in the binary number system. All integer values are expressed in computer memory by setting the values of binary digits. However, long binary digit sequences are difficult for us to deal with.

Suppose that we wanted to write out the binary form of a number such as the decimal 9587. We would find that 958710 = (10010101110011)2 The expression could be made somewhat more readable by grouping the digits.
 

Octal Representation

Suppose that we group them into threes. Then this might be written 958710 = (|010|010|101|110|011)2 where the | is used as a divider between groups of three. A zero has been added to fill out the group on the left end. Each of the clusters of three digits can be compressed to a single symbol by using the symbols listed in the following table:
 
Group 000 001 010 011 100 101 110 111
Symbol 0 1 2 3 4 5 6 7
Note that the symbols that are used to represent each group are the same as the integer value of each group. By using these symbols, the number can be expressed in a more compact form 958710 = (2|2|5|6|3). Because the symbols are the same as those that are used in base 8 counting, this is called octal notation. There is no need to maintain the partitions between the numbers. To make it clear that octal notation is used we can write 958710 = 225638

Computer notation does not easily handle subscripts. Hence, other notations have been invented. In IDL the notation for an octal number is "n or 'n'O. The number in our example would be written "22563 or '22563'O. The letters B or L can be used to indicate that a value is a byte or a long integer. "22563L or '22563'OL would be a long integer and "112B or '112'OB would be a byte. The largest possible byte integer is "377B. Can you explain why?

Hexadecimal Representation

Supppose that we group the binary digits into fours. Then we might write Then this might be written 958710 = (|0010|0101|0111|0011|)2 Now the groups of four can be given different symbols. There are 16 different combinations of four binary digits. The symbols chosen are the common numerals plus the letters a,b,c,d,e,f. The letters may be either upper or lower case. The symbol table is
 
Group 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Symbol 0 1 2 3 4 5 6 7 8 9 A B C D E F

With this notation, the number would be represented as 958710 = 257316  This is called the hexadecimal representation. In IDL the number would be represented as '2573'X. To denote a byte or long integer one would use the notation '2573'XB or '2573'XL. The largest possible byte value is 'FF'XB. The largest possible integer is '7FFF'X. The largest possible long integer is '7FFFFFFF'X. Can you explain why?