review of number systems and codes

Preview:

Citation preview

The negative number has two representations:

a. complement representation

b. sign magnitude representation

Complement representation:

There are two ways of representing complement

numbers:

a. 1’s Complement

b. 2’s Complement

1’s complement of a binary number is obtained simply

by replacing each 1 by 0 and each 0 by 1. Alternately,

1’s complement of a binary can be obtained by

subtracting each bit from 1.

Example: Find 1’s complement of (i) 011001 (ii)

00100111

Solution. (i) Replace each 1 by 0 and each 0 by 1

0 1 1 0 0 1

↓ ↓ ↓ ↓ ↓ ↓

1 0 0 1 1 0

So, 1’s complement of 011001 is 100110.

(ii) Subtract each binary bit from 1.

1 1 1 1 1 1 1 1

–0 0 1 0 0 1 1 1

1 1 0 1 1 0 0 0 ← 1’s complement

one can see that both the method gives sameresult.

2’s Complement

2’s complement of a binary number can be obtainedby adding 1 to its 1’s complement.

Example 1. Find 2’s complement of (i) 011001 (ii)0101100

Solution. (i) 0 1 1 0 0 1 ← Number

1 0 0 1 1 0 ← 1’s complement

+ 1 ← Add 1 to 1’s complement

1 0 0 1 1 1 ← 2’s complement

(ii) 0 1 0 1 1 0 0 ← Number

1 0 1 0 0 1 1 ← 1’s complement

+ 1 ← Add 1 to 1’s complement

1 0 1 0 1 0 0 ← 2’s complement

Before using any complement method for subtraction

equate the length of both minuendand subtrahend by

introducing leading zeros.

1’s complement subtraction following are the rules for

subtraction using 1’s complement.

1. Take 1’s complement of subtrahend.

2. Add 1’s complement of subtrahend to minuend.

3. If a carry is produced by addition then add this carry to the

LSB of result. This is called as end around carry (EAC).

4. If carry is generated from MSB in step 2 then result is

positive. If no carry generated result is negative, and is in

1’s complement form.

Example. Perform following subtraction using

1’s complement.

(i) 7 – 3 (ii) 3 – 7

Solution. (i) 7 – 3:

binary of 7 = (0111)2

binary of 3 = (0011)2

both numbers have equal length.

Step 1. 1’s complement of (0011)2 = (1100)2

In a broad sense we can classify the codes into

five groups:

(i) Weighted Binary codes

(ii) Non-weighted codes

(iii) Error–detecting codes

(iv) Error–correcting codes

(v) Alphanumeric codes.

In weighted binary codes, each position of a number

represents a specific weight. The bits are multiplied by the

weights indicated; and the sum of these weighted bits gives

the equivalent decimal digit.

(a) Straight Binary coding is a method of representing a

decimal number by its binary equivalent.

In BCD codes, individual decimal digits are coded in

binary notation and are operated upon singly. Thus

binary codes representing 0 to 9 decimal digits are

allowed. Therefore, all BCD codes have at least

four bits (∵ min. no. of bits required to encode to

decimal digits = 4)

For example, decimal 364 in BCD

3 → 0011

6 → 0110

4 → 0100

364 → 0011 0110 0100

There are many binary coded decimal codes(BCD) all of which are used to represent decimaldigits. Therefore, all BCD codes have atleast 4bits and at least 6 unassigned or unused codewords.

Some example of BCD codes are:

(a) 8421 BCD code, sometimes referred to as the Natural Binary Coded Decimal Code (NBCD);

(b)* Excess-3 code (XS3);

(c)** 84 –2 –1 code (+8, +4, –2, –1);

(d) 2 4 2 1 code

Example: Lowest [643]10 into XS3 code

Decimal 6 4 3

Add 3 to each 3 3 3

Sum 9 7 6

Converting the sum into BCD code we have

9 7 6

↓ ↓ ↓

1001 0111 0110

Hence, XS3 for [643]10 = 1001 0111 0110

The excess 3, 8 4–2–1 and 2421 BCD codes are also known

as self complementing codes.

Self complementing property– 9’s complement of the

decimal number is easily obtained by changing 1’0 to 0’s

and 0’s to 1’s in corresponding codeword or the 9’s

complement of self complementing code word is the same

as its logical complement.

Example. The decimal digit 3 in 8.4–2–1 code is coded as

0101. The 9’s complement of 3 is 6. The decimal digit 6 is

coded as 1010 that is 1’s complement of the code for 3. This

is termed as self complementing property.

These codes are not positionally weighted.

This means that each position within a binary

number is not assigned a fixed value.

Excess-3 codes

Gray codes

are examples of nonweighted codes.

Gray code (Unit Distance code or Reflective code)

There are applications in which it is desirable to representnumerical as well as other information with a code thatchanges in only one bit position from one code word to thenextadjacent word.

This class of code is called a unit distance code (UDC).

These are sometimes also called as ‘cyclic’, ‘reflective’ or‘gray’ code.

These codes finds great applications in Boolean functionminimization using Karnaugh map.

Binary information is transmitted from one device toanother by electric wires or other communication medium.

A system that can not guarantee that the data received byone device are identical to the data transmitted by anotherdevice is essentially useless.

Yet anytime data are transmitted from source to destination,they can become corrupted in passage. Many factors,including external noise, may change some of the bits from0 to 1 or viceversa.

Reliable systems must have a mechanism for detecting andcorrecting such errors.

In a single bit error, a 0 is changed to a 1 or a 1 ischanged to a 0.

In a burst error, multiple (two or more) bits arechanged.

The purpose of error detection code is to detect such bitreversal errors.

Error detection uses the concept of redundancy whichmeans adding extra bits for detecting errors at thedestination.

Four types of redundancy checks are used:

Parity check or vertial redundancy check(VRC)

longitudinal redundancy check (LRC)

cyclic redundancy check (CRC) and

checksum

For a single bit error detection, the most common way

to achieve error detection is by means of a parity bit

A parity bit is an extra bit (redundant bit) included with

a message to make the total number of 1’s transmitted

either odd or even.

In LRC, a block of bits is organised in rows and columns

(table). For example, a block of 16 bits can be organised in

two rows and eight columns as shown in Fig.

We then calcualte the parity bit (even parity/odd parity, here

we are using even parity) for each column and create a new

row of 8 bits, which are the parity bits for the whole block.

CRC is most powerful of the redundancy checkingtechniques.Cyclic redundancy check is based onbinary division.

A sequence of redundant bits called CRC or CRCremainder is appended to the end of a data unit.

After adding CRC remainder, the resulting dataunit becomes exactly divisible by anotherpredetermined binary number.

At the destination this data unit is divided by thesame binary number. If there is no remainder,then there is no error.

The CRC generator and CRC checker are

shown in Fig.(a) and Fig.(b) respectively.

Fig.(a) Fig.(b)

The mechanism that we have covered upto this

point detect errors but do not correct them. Error

correction can be handled in two ways.

In one, when an error is encountered the receiver

can request the sender to retransmit entire data

unit.

In the other, a receiver can use an error correcting

code, which automatically corrects certain errors.