COMPUTER CODES
Although the capacity of their storage locations can vary,every computer stores numbers,letters,and other characters in a coded form.
Every character in storage is represented by a string of 0s and 1s—the only digits found in the binary numbering system. Let’s see how it’s possible to use just two digits to represent any character.
Most computers use a coded version of true binary to represent decimal numbers.
Although many coding schemes have been developed over the years,the most popular of these use a binary coded decimal(BCD)approach.
The BCD Approach.
With BCD,it’s possible to convert each decimal number into its binary equivalent rather than convert the entire decimal value into a pure binary form.
The BCD equivalent of each possible symbol is shown in Fig.1-3.
Since 8 and 9 require 4 bits,all decimal digits are presented in BCD by 4 bits.
You’ve just seen that 202 is equal to 1100 1010 in a pure binary form.
Converting 202 into BCD,however,produces the following result:202(10)in BCD=0010 0000 0010 or 0010 0000 0010

Six-bit BCD Code.
Instead of using 4 bits with only 16 possible characters,computer designers commonly use 6,7,8 bits to represent characters in alphanumeric versions of BCD.
In the 6-bit code,the four BCD numeric place positions(1,2,4,and 8)are retained,but two additional zone positions are included(Fig. 1-4(a)).
With 6 bits,it’s possible to represent 64 different characters(26).
This is a sufficient number to code the decimal digits(10),capital letters(26),and other special characters and punctuation marks(28).
Fig. 1-4(b)shows you how a few of the 64 possible characters are represented in a standard 6-bit BCD code.
Seven and Eight-Bit Codes.
Since 64 possible bit combinations isn’t sufficient to provide decimal numbers(10),lower-case letters(26),capital letters(26),and a large number of other characters (28),designers have extended the 6-bit BCD code to 7 and 8 bits.
With 7 bits,it’s possible to provide 128 different arrangements(27);with 8 bits,256 variations are possible(28).
In addition to the four numeric place positions,there are three zone bit positions in a 7-bit code,and four zone bit positions in an 8-bit code.
The 7-bit American Standard Code for Information Interchange(ASCII)is widely used in data communications work and is by far the most popular code used to represent data internally in personal computers.
The ASCII format and the coding used to represent selected characters are shown in Fig. 1-5.
These are other two 8-bit codes in common use.
One is the Extended Binary Coded Decimal Interchange Code(EBCDIC).
This code is used in IBM mainframe models and in similar machines produced by other manufactures.
The other 8-bit code is ASCII-8,an 8-bit version of ASCII that is frequently used in the larger machines produced by some vendors.
Fig. 1-6 presents the 8-bit format and shows how selected characters are represented in these 8-bit codes. The main difference is in the selection of bit patterns to use in the zone positions.

计算机代码
尽管计算机存储单元的容量可大可小,但是每台计算机都是以代码形式存储数、字母和其他字符的。
存储器中的每个字符都用0、1(二进制编码系统中仅有的两个数字)串表示。下面让我们看看如何只用两个数字来表示任何字符。
大多数计算机用准确的二进制编码方法表示十进制数。
多年来研制了许多编码方案,其中最流行的是二进制编码的十进制(BCD)方案。
BCD方案:用BCD码,可以将十进制数的每一位转换成相等的二进制数,而不是将整个十进制数的值转换成纯二进制数的形式。各十进制数位对应的BCD码如图1-3所示。因为8和9需要4位二进制数表示,所以,所有十进制数位均用4位BCD码表示。众所周知,用纯二进制数表示202等于11001010,但是将202转换成BCD码,结果如下:202(10)的BCD码 = 0010 0000 0010或001000000010。
6位BCD码。计算机设计者普遍采用6位、7位或8位BCD字母数字型字符来代替只有16种可能字符的4位BCD码。在6位BCD码中,4位BCD数字位(1,2,4,8)仍保留,但是,包含了两个附加的标志位,如图1-4(a)所示。用6位二进制数可以表示64个不同字符(26)。这对十进制数字(10个)、大写字母(26个)及其他特殊字符和标点符号(28个)进行编码已经够用。其中,几个对应的标准6位BCD码字符如图1-4(b)所示。
7位和8位编码。因为64种可能的位排列仍不能满足十进制数(10个)、小写字母(26个)、大写字母(26个)和大量的其他字符(28个)编码的需要,所以设计者将6位BCD码扩充到7位和8位。7位二进制数可以提供128种不同的排列(27);而8位二进制数可以有256种排列(28)。除了4位数字位之外,在7位编码中有3个标志位,在8位编码中则有4个标志位。7位美国信息交换用标准代码(ASCII)广泛地用于数据通信,而且是目前个人计算机内部数据表示中最为流行的代码。ASCII码的格式及所选字符的编码如图1-5所示。
还有另外两种普遍使用的8位编码。一种是扩展的二-十进制交换码(EBCDIC),该编码用于IBM大型计算机及其他厂家生产的类似机器中;另一种8位编码是ASCII-8,是ASCII代码8位格式,常用于一些厂商生产的较大机器中。8位编码的格式及如何表示所选字符如图1-6所示。这两种编码的主要区别在于标志位模式的选择。