Why are the keyboard scan codes for digits off by one?

Raymond Chen

In Off by one what, exactly?, my colleague Michael Kaplan wrote

And this decision long ago that caused the scan codes to not line up for these digits when they could have…

The word that struck me there was “decision”.

Because it wasn’t a “decision” to make the scan codes almost-but-not-quite line up with digits. It was just a coincidence.

If you look at the scan code table from Michael’s article

you can see stretches of consecutive scan codes, broken up by weird places where the consecutive pattern is violated. The weirdness makes more sense when you look at the original IBM PC XT keyboard:

01
Esc
02
1
03
2
04
3
05
4
06
5
07
6
08
7
09
8
0A
9
0B
0
0C
0D
=
0E
0F
10
Q
11
W
12
E
13
R
14
T
15
Y
16
U
17
I
18
O
19
P
1A
[
1B
]
1C
1D
Ctrl
1E
A
1F
S
20
D
21
F
22
G
23
H
24
J
25
K
26
L
27
;
28
29
`
2A
2B
\
2C
Z
2D
X
2E
C
2F
V
30
B
31
N
32
M
33
,
34
.
35
/
36
37
*
38
Alt
39
Space
3A
Caps

With this presentation, it becomes clearer how scan codes were assigned: They simply started at 01 and continued through the keyboard in English reading order. (Scan code 00 is an error code indicating keyboard buffer overflow.) The reason for the keyboard scan code being off-by-one from the digits is merely due to the fact that there was one key to the left of the digits. If there were two keys to the left of the digits, they would have been off by two.

Of course, if the original keyboard designers had started counting from the lower left corner, like all right-thinking mathematically-inclined people, then this sort-of-coincidence would never have happened. The scan codes for the digits would have been 2E through 37, and nobody would have thought anything of it.

It’s a testament to the human brain’s desire to find patterns and determine a reason for them that what is really just a coincidence gets interpreted as some sort of conspiracy.

0 comments

Discussion is closed.

Feedback usabilla icon