Sei sulla pagina 1di 8

ShrutiKhatri

COMPUTER CODING SYSTEMS


To represent numeric, alphabetic, and special characters in a computer's internal storage and on
magnetic media, we must use some sort of coding system. In computers, the code is made up of
fixed size groups of binary positions. Each binary position in a group is assigned a specific
value; for example 8, 4, 2, or 1. In this way, every character can be represented by a combination
of bits that is different from any other combination.
Binary Code
A binary code is a way of representing text or computer processor instructions by the use of
the binary number system's two-binary digits 0 and 1. This is accomplished by assigning a bit
string to each particular symbol or instruction. For example, a binary string of eight binary digits
(bits) can represent any of 256 possible values and can therefore correspond to a variety of
different symbols, letters or instructions.
In computing and telecommunication, binary codes are used for any of a variety of methods
of encoding data, such as character strings, into bit strings. Those methods may be fixed-width
or variable-width. In a fixed-width binary code, each letter, digit, or other character, is
represented by a bit string of the same length; that bit string, interpreted as a binary number, is
usually displayed in code tables in octal, decimal or hexadecimal notation. There are
many character sets and many character encodings for them.
A bit string, interpreted as a binary number, can be translated into a decimal number. For
example, the lowercase "a" as represented by the bit string 01100001, can also be represented as
the decimal number 97.
Binary-coded Decimal
Binary-coded decimal, or BCD, is a binary encoded representation of integer values that uses a
4-bit nibble to encode decimal digits. Four binary bits can encode up to 16 distinct values; but, in
BCD-encoded numbers, only the first ten values in each nibble are legal, and encode the decimal
digits zero, through nine. The remaining six values are illegal, and may cause either a machine
exception or unspecified behavior, depending on the computer implementation of BCD
arithmetic.
BCD arithmetic is sometimes preferred to floating-point numeric formats in commercial and
financial applications where the complex rounding behaviors of floating-point numbers is
inappropriate.
Counting in binary
Decimal pattern (Hex Value) Binary numbers
0

1|P a g e

ShrutiKhatri

Counting in binary is similar to counting in 2


any other number system. Beginning with a
single digit, counting proceeds through each 3
symbol, in increasing order. Decimal counting
uses the symbols 0 through 9, while binary 4
only uses the symbols 0 and 1.

10

When the symbols for the first digit are 5


exhausted, the next-higher digit (to the left) is
incremented, and counting starts over at 0. 6
In decimal, counting proceeds like so:
7
000, 001, 002, ... 007, 008, 009, (rightmost
digit starts over, and next digit is incremented) 8

101

11
100

110
111
1000

010, 011, 012, ...


...

090, 091, 092, ... 097, 098, 099, (rightmost


10 - (A)
two digits start over, and next digit is
incremented)
11 - (B)
100, 101, 102, ...
12 - (C)
After a digit reaches 9, an increment resets it
to 0 but also causes an increment of the next
digit to the left. In binary, counting is the same 13 - (D)
except that only the two symbols 0 and 1 are
used. Thus after a digit reaches 1 in binary, an 14 - (E)
increment resets it to 0 but also causes an
15 - (F)
increment of the next digit to the left:
0000,

16 - (10)

1001
1010
1011
1100
1101
1110
1111
10000

0001, (rightmost digit starts over, and next


digit is incremented)
0010, 0011, (rightmost two digits start over, and next digit is incremented)
0100, 0101, 0110, 0111, (rightmost three digits start over, and the next digit is incremented)
1000, 1001, ...

Since binary is a base-2 system, each digit represents an increasing power of 2, with the
rightmost digit representing 20, the next representing 21, then 22, and so on. To determine the
decimal representation of a binary number simply take the sum of the products of the binary
digits and the powers of 2 which they represent. For example, the binary number:
2|P a g e

ShrutiKhatri

100101 is converted to decimal form by:


[(1) 25] + [(0) 24] + [(0) 23] + [(1) 22] + [(0) 21] + [(1) 20] =
[1 32] + [0 16] + [0 8] + [1 4] + [0 2] + [1 1] = 37
To create higher numbers, additional digits are simply added to the left side of the binary
representation.
Gray Code
GrayCode
This is a variable weighted code and is cyclic. This means that it is arranged so that every
transition from one value to the next value involves only one bit change. The gray code is
sometimes referred to as reflected binary, because the first eight values compare with those of the
last 8 values, but in reverse order.
The gray code is often used in mechanical applications such as shaft
encoders.
Modulo2Arithmetic
This
is
binary
addition
with
the
carry
ignored.
Converting
Gray
Code
to
Binary
A. write down the number in gray code.

Decimal Binary Gray


0

0000

0000

0001

0001

0010

0011

0011

0010

0100

0110

B. the most significant bit of the binary number is the most significant bit 5
of the gray code.
6

0101

0111

0110

0101

0111

0100

1000

1100

1001

1101

10

1010

1111

11

1011

1110

12

1100

1010

13

1101

1011

14

1110

1001

15

1111

1000

C. add (using modulo 2) the next significant bit of the binary number to
the next significant bit of the gray coded number to obtain the next binary
bit
D. repeat step C till all bits of the gray coded number have been added
modulo
2
the resultant number is the binary equivalent of the gray number

3|P a g e

ShrutiKhatri

Convert natural binary 11001010 to gray code.

Step 1) Copy most significant bit (on very left)

Answer: 1

Step 2) Add from left to right bit by bit of your binary number:

(1+1) 001010 [1+1 = 0]

Answer: 10

Step 3) Continue:

1(1+0)01010
Answer: 101

------------------------11(0+0)1010
Answer: 1010

-----------------------110(0+1)010
Answer: 10101

------------------------until you get to the end

110010(1+0)
Answer: 10101111 <- Answer in Gray Code.

Gray code is where only one bit changes at a time. Binary code is where one or more bits change
at a time. An example, for three bits, with binary on the left and gray on the right, with the
changing bits underlined...
000
000
001 001
010 011
011 010
4|P a g e

ShrutiKhatri

100 110
101 111
110 101
111 100
000 000 Repeating...
The advantage of binary code is that it is easy to convert to a numeric value. The advantage of
gray code is that it makes very stable position digitizers, because only one bit changes at a time,
resulting in uncertainty of only one bit.

EXTENDED BINARY CODED DECIMAL INTERCHANGE CODE (EBCDIC)


Using an 8-bit code, it is possible to represent 256 different characters or bit combinations. This
provides a unique code for each decimal value 0 through 9 (for a total of 10),
each uppercase and lowercase letter (for a total of 52), and for a variety of special characters. In
addition to four numeric bits, four zone bit positions are used in 8-bit code as illustrated in figure
. Each group of the eight bits makes up one alphabetic, numeric, or special character and is called
a byte.
Figure . - Format for EBCDIC and ASCII codes.

When you look at figure 4-3, you will notice that the four rightmost bits in EBCDIC are assigned
values of 8, 4, 2, and 1. The next four bits to the left are called the zone bits. The EBCDIC
coding chart for uppercase and lowercase alphabetic characters and for the numeric digits 0
through 9 is shown in figure 4-4, with their hexadecimal equivalents. Hexadecimal is a number
system used with some computer systems. It has a base of 16 (0-9 and A-F). A represents 10; B
represents 11; C represents 12; D represents 13; E represents 14; and F represents 15. In
EBCDIC, the bit pattern 1100 is the zone combination used for the alphabetic characters A
through I, 1101 is used for the characters J through R, and 1110 is the zone combination used for
characters S through Z. The bit pattern 1111 is the zone combination used when representing
decimal digits. For example, the code 11000001 is equivalent to the letter A; the code 11110001
is equivalent to the decimal digit 1. Other zone combinations are used when forming special
characters. Not all of the 256 combinations of 8-bit code have been assigned characters. Figure
4-5 illustrates how the characters DP-3 are represented using EBCDIC.
Figure . - Eight-bit EBCDIC coding chart (including exadecimal equivalents).

5|P a g e

ShrutiKhatri

Figure . - DP-3 represented using 8-bit EBCDIC code.


DP - 31100 01001101 01110110 00001111 0011
Since one numeric character can be represented and stored using only four bits (8-4-2-1), using
an 8-bit code allows the representation of two numeric characters (decimal digits) as illustrated
in figure . Representing two numeric characters in one byte (eight bits) is referred to
as packing or packed data. By packing data (numeric characters only) in this way, it allows us
to conserve the amount of storage space required, and at the same time, increases processing
speed.
Figure . - Packed data.
DECIMAL VALUE

92

73

EBCDIC

10010010 01110011

BIT PLACE VALUES 84218421 8421


8421

BYTE1 BYTE2
6|P a g e

ShrutiKhatri

AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE (ASCII)


Another 8-bit code, known as the American Standard Code for Information Interchange (ASCII)
(pronounced ASS-KEY), was originally designed as a 7-bit code. Several computer
manufacturers cooperated to develop this code for transmitting and processing data. The
purpose was to standardize a binary code to give the computer user the capability of using
several machines to process data regardless of the manufacturer:
IBM, HONEYWELL, UNIVAC, BURROUGHS, and so on. However, since most computers are
designed to handle (store and manipulate) 8-bit code, an 8-bit version of ASCII was developed.
ASCII is commonly used in the transmission of data through data communications and is used
almost exclusively to represent data internally in microcomputers.
The concepts and advantages of ASCII are identical to those of EBCDIC. The important
difference between the two coding systems lies in the 8-bit combinations assigned to represent
the various alphabetic, numeric, and special characters. When using ASCII 8-bit code, you will
notice the selection of bit patterns used in the positions differs from those used in EBCDIC. For
example, let's look at the characters DP3 in both EBCDIC and ASCII to see how they compare.
Character D

EBCDIC 1100 0100 1101 0111 1111 0011


ASCII

0100 0100 0101 0000 0011 0011

In ASCII, rather than breaking letters into three groups, uppercase letters are assigned codes
beginning with hexadecimal value 41 and continuing sequentially through hexadecimal
value 5A. Similarly, lowercase letters are assigned hexadecimal values of 61 through 7A.
The decimal values 1 through 9 are assigned the zone code 0011 in ASCII rather that 1111 as in
EBCDIC. Figure is the ASCII coding chart showing uppercase and lowercase alphabetic
characters and numeric digits 0 through 9.
Figure - Eight-bit ASCII coding chart (including hexadecimal equivalents).

7|P a g e

ShrutiKhatri

At this point you should understand how coding systems are used to represent data in both
EBCDIC and ASCII. Regardless of what coding system is used, each character will have an
additional bit called a check bit or parity bit.
PARITY BIT
This additional check or parity bit in each storage location is used to detect errors in the circuitry.
Therefore, a computer that uses an 8-bit code, such as EBCDIC or ASCII, will have a ninth bit
for parity checking.
The parity bit (also called a check bit, the C position in a code) provides an internal means for
checking the validity, the correctness, of code construction. That is, the total number of bits in a
character, including the parity bit, must always be odd or always be even, depending upon
whether the particular computer system or device you are using is odd or even parity. Therefore,
the coding is said to be in either odd or even parity code, and the test for bit count is called
a parity check.

8|P a g e

Potrebbero piacerti anche