Classic Computer Magazine Archive COMPUTE! ISSUE 58 / MARCH 1985 / PAGE 10

READERS' FEEDBACK

The Editors and Readers of COMPUTE!

Computer Counting
I don't understand the difference between ASCII, hexadecimal, and decimal numbers.
Don Lyles

ASCII (pronounced "as-key") is an acronym for American Standard Code for Information Interchange. It is a standard code used for communication between computers. Among other things, it lets different types of computers communicate with each other using telephone modems.
    Each ASCII number stands for a character. For instance, the ASCII code 65 stands for the uppercase letter A. Because an ASCII number consists of one byte containing eight bits, there are 256 possible code numbers (2 to the eighth power). But only the first 128 characters are defined by ASCII, while the remaining 128 characters are different on each computer. Some computers tinker with the first 128 codes, too, creating their own version of ASCIIsuch as PETASCII (Commodore ASCII) or ATASCII (Atari ASCII). Departures from regular ASCII can cause compatibility problems when these computers try to communicate with other computers.
    The figure below shows the 128 standardized characters which make up the ASCII character set:

 
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F


0
0000000
NUL
 
0
0000001
SOH
^A
1

0000010
STX
^B
2

0000011
ETX
^C
3

0000100
EOT
^D
4

0000101
ENQ
^E
5

0000101
ACK
^F
6

0000111
BEL
^G
7
0001000
BS
^H
8

0001001
HT
^I
9

0001010
LF
^J
10

0001011
VT
^K
11

0001100
FP
^L
12

0001101
CR
^M
13

0001110
SO
^N
14

0001111
SI
^O
15

001000
DLE
^P
16

0010001
DC1
^Q
17

0010010
DC2
^R
18

0010011
DC3
^S
19

0010100
DC$
^T
20

0010101
NAK
^U
21

0010110
SYN
^V
22

0010111
ETB
^W
23

0011000
CAN
^X
24

0011001
EM
^Y
25

0011011
SUB
^Z
26

0011100
ESC
 
27

0011101
FS
 
28

0011101
GS
 
29

0011110
RS
 
30

0011111
US
 
31

0100000
SPACE
32

0100001
!
32

0100010
"
34
0100011
#
35
0100100
$
36
0100101
%
37
0100110
&
38
0100111
'
39
0101000
(
40
0101001
)
41
0101010
*
42
0101011
+
43
0101100
,
44
0101101
-
45
0101110
.
46
0101111
/
47
0110000
0
48
0110001
1
49
0110010
2
50
0110011
3
51
0110100
4
52
0110101
5
53
0110110
6
54
0110111
7
55
0111000
8
56
0111001
9
57
0111010
:
58
0111011
;
59
0111100
<
60
0111101
=
61
0111110
>
62
0111111
?
64
1000000
@
64
1000001
A
65
10000010
B
66
1000011
C
67
1000100
D
68
1000101
E
69
1000110
F
70
1000111
G
71
1001000
H
72
1001001
I
73
1001010
J
74
1001011
K
75
1001100
L
76
1001101
M
77
1001110
N
78
1001111
O
79
1010000
P
80
1010001
Q
81
1010010
R
82
1010011
S
83
1010100
T
84
1010101
U
85
1010110
V
86
1010111
W
87
1011000
X
88
1011001
Y
89
1011010
Z
90
1011011
[
91
1011100
\
92
1011101
]
93
1011110
^
94
1011111
_
95
1100000
`
96
1100001
a
97
1100010
b
98
1100011
c
99
1100100
d
100
1100101
e
101
1100110
f
102
1100111
g
103
1101000
h
104
1101001
i
105
1101010
j
106
1101011
k
107
1101100
l
108
1101101
m
109
1101110
n
110
1101111
o
111
1110000
p
112
1110001
q
113
1110010
r
114
1110011
s
115
1110100
t
116
1110101
u
117
1110110
v
118
1110111
w
119
1111000
x
120
1111001
y
121
1111010
z
122
1111011
{
123
1111100
|
124
1111101
}
125
1111110
~
126
1111111
DEL
127


1


2


3


4


5

6


7


    As you examine the figure, you'll notice some rather unusual designations. Not all ASCII numbers stand for characters you would normally recognize. These are control codes and are considered to be nonprinting machine instruction characters. In other words, instead of printing a character on the screen, they perform some function-such as clearing the screen, moving the cursor, or forcing a carriage return or linefeed.
    To answer the second part of your question, decimal and hexadecimal are just two different numbering systems, not coding systems like ASCII. Decimal is the system we normally use, sometimes called base 10 because it's based on 10 digits-0 through 9. Hexadecimal is base 16 and uses 16 digits-0 through 9 plus A, B, C D, E, and F (any symbols could have been chosen to represent the extra six digits, but A-F were selected because they're commonly available on keyboards).
    When counting in hexadecimal, just as in decimal, you don't start using two-digit numbers until you've run out of one-digit numbers. For example, in decimal you count 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and then 10. In hexadecimal, you would count 0, 1, 2, 3, 4,5,6,7,8,9, A, B, C, D, E, F, and then 10. Notice that A in hexadecimal equals 10 in decimal, B equals 11, C equals 12, and so on. Therefore, hexadecimal 10 equals decimal 16. In any numbering system, the first two-digit number-represented as 10-always equals the base of that system. (Incidentally, we might be using the hexadecimal system for everyday counting if humans were born with 16 fingers instead of 10.)
    It's not too important to learn hexadecimal unless you want to write programs in machine language. Machine language programmers use the hexadecimal numbering system (and sometimes the base 8 system, called octal) because it's a more compact way of writing binary numbers and a more efficient way of visualizing binary patterns. Binary, in turn, is the base 2 numbering system-it uses only the digits 0 and 1. Computers "think" in binary and are programmed that way on the machine language level. But binary numbers take up lots of space when written down, and they are difficult to read. For instance, the binary number 11010010 is eight digits long and is hard to interpret at a glance. Expressed in decimal, 11010010 equals 210-a threedigit number that obscures the binary pattern. Expressed in hexadecimal, 11010010 equals D2, a more compact number which an experienced programmer can break down into two parts-D = 1101 and 2 = 0010. This can be very important in machine language programming.
    Because machine language programmers are likely to encounter decimal, hexadecimal, and binary numbers in books, magazines, and program listings, special symbols have been agreed upon to. keep the different systems from being confused with each other. Otherwise, the number 100 could be interpreted to have a decimal value of 100 in decimal, 64 in hexadecimal, or 4 in binary. Needless to say, this could result in a programming snafu that would leave the computer pretty confused, too. Many programmers use the dollar sign ($) to denote hexadecimal and the percent sign (%) to denote binary. So $FF means hexadecimal FF, which equals 255 in decimal. Other programmers use the letter H to represent hexadecimal, so $FF would be written FFH. A number with no special symbol is assumed to be decimal.
    For a more thorough discussion of these numbering systems, consult a programming book, such as Machine Language for Beginners, Programming the VIC, Programming the 64, or Programming the PET/CBM from COMPUTE! Books.