Number System and Codes

  • Upload
    vsbist

  • View
    49

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to Number System and Codes

Citation preview

  • 1

    Number Systems and codes

    Dr. V. S. Bist, STO (Electronics),

    USIC, HNB Garhwal University, Srinagar (Garhwal) 246174, India E-Mail:[email protected]

    1. Introduction Number systems are useful in digital computers and the knowledge of these systems is

    necessary to perform reliable, economic and easily under stable arithmetic operations.

    The term digital implies to a system of counting discrete units. A physical system whose

    behaviour is described by mathematical equations is simulated in a digital computer by

    means of number systems. This chapter provides only a basic introduction to Number

    systems and codes.

    1.1 Digital systems Digital system has such a prominent role in everyday life that we refer to the present

    technological period as the digital age. Logic circuits are the basis for modern digital

    computer systems. To appreciate how computer systems operate you will need to

    understand digital logic and Boolean algebra. First we start out with the concept of digital

    vs. analog. In binary number, we can name according to number of bits (Bit: Binary

    digit) given in table 1.

    Table 1: Nomenclature according to the number of bits used.

    Number of bits Nomenclature

    one Binary

    two Crumb, Tydbit or Tayste

    four NibbleorNybble

    five Nickle

    Eight bits Byte

    Ten bit Deckle

    Sixteen bits Playte

    Thirty two bits Dynner

    Word System dependent

    1.1.1 Digital vs. Analog The term digital refers to the fact that the signal is limited to only a few possible values.

    In general, digits signals are represented by only two possible voltages on a wire - 0 volts

    (which we called "binary 0", or just "0") and 5 volts (which we call "binary 1", or just

    "1"). We sometimes call these values "low" and "high", or "false" and "true". More

    complicated signals can be constructed from 1s and 0s by stringing them end-to-end, like

    a necklace. If we put three binary digits end-to-end, we have eight possible combinations:

    000, 001, 010, 011, 100, 101, 110 and 111. In principle, there is no limit to how many

    binary digits we can use in a signal, so signals can be as complicated as you like. The

    figure 1 below shows a typical analog and digital signal, firstly represented as a series of

    voltage levels that change as time goes on, and then as a series of 1s and 0s.

    Digital signals are the language of modern day computers. Digital signals comprise only

    two states. These are expressed as ON or OFF, 1 or 0 respectively. Examples of devices

    having TWO states in the home are, (i) Light Switches: Either ON or OFF (ii) Doors:

    Either OPEN or CLOSED. Digital signal require greater bandwidth capacity than

  • 2

    analogue signals, thus are more expensive to communicate. This diagram shows a digital

    signal.

    Figure 1.(a) A digital Signal (b) An analog signal

    Analog electronics uses voltages that can be any value (within limits, of course - it's

    difficult to imagine a radio with voltages of a million volts). The voltages often change

    smoothly from one value to the next, like gradually turning a light dimmer switch up or

    down. The public dial-up service supports analogue signals. Analogue signals are what

    we encounter every day of our life. Speech is an analogue signal, and varies in amplitude

    (volume), frequency (pitch), and phase. The figure below shows an analog signal that

    change with time.

    1.2 Number systems Many number systems are in use in digital technology. The most common are the

    decimal, binary, octal, and hexadecimal systems. The decimal system is clearly the most

    familiar to us because it is a tool that we use every day. Examining some of its

    characteristics will help us to help us to better understand the other systems. There are

    different number systems some of them are given in the following table.

    Number System

    base-2 (Binary)

    base-7 (Septenary)

    base-12 (Duodecimal)

    base-3 (Trinary)

    base-8 (Octal)

    base-13 (Tridecimal)

    base-4(Quaternary)

    base-9 (Nonary)

    base-14 (Quattuordecimal)

    base-5 (Quinary)

    base-10 (Decimal)

    base-15 (Quindecimal)

    base-6 (Qenary)

    base-11 (Undenary)

    base-16 (Hexadecimal)

    Table 2: Different Number System But in nature, Binary, octal, decimal and hexadecimal is most commonly used number system.

  • 3

    1. Binary System:

    In the binary system, there are only two symbols or possible digit values, 0 and 1. This

    base-2 system can be used to represent any quantity that can be represented in decimal or

    other base system.

    23 22 21 20 . 2-1 2-2 2-3

    =8 =4 =2 =1 Binary

    point

    =0.5 =0.25 =0.125

    MSB LSB

    2. Decimal System:

    In the decimal system, there are ten symbols or possible digit values, 0 to 9. This

    base-10 system can be used to represent any quantity that can be represented in binary

    or other base system.

    103 102 101 100 . 10-1 10-2 10-3

    =1000 =100 =10 =1 Decimal

    point

    =0.1 =0.01 =0.001

    MSD LSD

    3. Octal System: The octal number system has a base of eight, meaning that it has eight possible digits:

    0, 1,2,3,4,5,6,7.

    83 82 81 80 . 8-1 8-2

    = 512 = 64 = 8 =1 Octal

    point

    =0.125 =0.015625

    MSB LSB

    4. Hexadecimal System: The hexadecimal system uses base 16. Thus, it has 16 possible digit symbols. It uses

    the digits 0 through 9 plus the letters A, B, C, D, E, and F as the 16 digit symbols.

    163 162 161 160 . 16-1 16-2

    =4096 =256 = 16 =1 Hexadecimal

    point

    =0.0625 =0.00390

    MSB LSB

    General rule for representing any number system (base r) by using positional notation

    is as follows:

    )...................(

    ).......(

    Fractionalpoint)(radixInteger

    part)FractionalpartInteger(

    321

    0

    0

    1

    1

    2

    2

    3

    3

    2

    2

    1

    1

    ........321.012321

    r

    n

    m

    nnnn

    n

    n

    n

    n

    n

    rmnnn

    rarararararararararara

    aaaaaaaaaaa

    Lets count from zero to ten using the decimal number system and the other number system. Generally we use the decimal, binary, octal and hexadecimal numbers. In

  • 4

    addition, the following list includes ternary (or trinary, base-3), quaternary (base-4) and

    dozenal (or duodecimal, base-12) numbers, which are more unusual.

    Radix Base Number Number Containing

    Binary- Base 2: 0 to 1 10 to 11 100 to 101 110 to 111 1000 to 1001 1010 to 1011 1100 to 1101

    Ternary- Base 3: 0 to 2 10 to 12 20 to 22 100 to 102 110 to 112 120 to 122 200 to 202

    Quaternary- Base 4: 0 to 3 10 to 13 20 to 23 30 to 33 100 to 103 110 to 113 120 to 123

    Quinary- Base 5: 0 to 4 10 to 14 20 to 24 30 to 34 40 to 44 100 to 104 110 to 114

    Senary- Base 6: 0 to 5 10 to 15 20 to 25 30 to 35 40 to 45 50 to 55 100 to 105

    Septenary- Base 7: 0 to 6 10 to 16 20 to 26 30 to 36 40 to 46 50 to 56 60 to 66

    Octal- Base 8: 0 to 7 10 to 17 20 to 27 30 to 37 40 to 47 50 to 57 60 to 67

    Nonary- Base 9: 0 to 8 10 to 18 20 to 28 30 to 38 40 to 48 50 to 58 60 to 68

    Decimal-

    (denary) Base 10:

    0 to 9 10 to 19 20 to 29 30 to 39 40 to 49 50 to 59 60 to 69

    Undenary- Base 11: 0 to A 10 to 1A 20 to 2A 30 to 3A 40 to 4A 50 to 5A 60 to 6A

    Duodenary- Base 12: 0 to B 10 to 1B 20 to 2B 30 to 3B 40 to 4B 50 to 5B 60 to 6B

    Hexadecimal- Base 16 0 to F 10 to 1F 20 to 2F 30 to 3F 40 to 4F 50 to 5F 60 to 6F

    Sexagesimal- Base 60 0 to F 10 to 1F 20 to 2F 30 to 3F 40 to 4F 50 to 5F 100 to 10F

    Table 3: Different Number System with number counting

    For clarity, octal numbers are prefixed by 0 and hexadecimal numbers by $. The numbers

    can, of course, be used without the prefix.

    Generally used Number system Others Number system Decimal

    Base-10

    Binary

    Base-2

    Octal

    Base-8

    Hex

    Base-16

    Ternary

    Base-3

    Quaternary

    Base-4

    Dozenal

    Base-12

    0 0 00 $0 0 0 0

    1 1 01 $1 1 1 1

    2 10 02 $2 2 2 2

    3 11 03 $3 10 3 3

    4 100 04 $4 11 10 4

    5 101 05 $5 12 11 5

    6 110 06 $6 20 12 6

    7 111 07 $7 21 13 7

    8 1000 010 $8 22 20 8

    9 1001 011 $9 100 21 9

    10 1010 012 $A 101 22 A

    11 1011 013 $B 102 23 B

    12 1100 014 $C 110 30 10

    13 1101 015 $D 111 31 11

    14 1110 016 $E 112 32 12

    15 1111 017 $F 120 33 13

    16 10000 020 $10 121 100 14

  • 5

    17 10001 021 $11 122 101 15

    18 10010 022 $12 200 102 16

    19 10011 023 $13 201 103 17

    20 10100 024 $14 202 110 18

    Table 4: Counting 20 Numbers in different Number System.

    1.3 Number-base conversion The binary number system is a natural choice for representing the behavior of circuits

    that operate in one of two states (on or off, 1 or 0). For instance, we studied a diode logic

    gate when we discussed diode circuits. But before we study logic gates, you need to be

    intimately familiar with the binary number system the system used by computers for counting.

    Notice, though, how much shorter decimal notation is over binary notation, for the same

    number of quantities? What takes five bits in binary notation only takes two digits in

    decimal notation.

    Notice that the binary number system and digital logic are actually two different

    concepts. A binary number is a number in base-2; it is independent of the concept of

    digital logic. However, the computer revolution is attributed to the very simple fact that

    mathematics in digital electronics can be represented by binary numbers. This is the

    number system that we will primarily study, along with the hexadecimal (base-16)

    system for convenience of representing large digits.

    1.3.1 Any number system to decimal: To convert any number system to its decimal equivalent, you have to do to calculate the

    sum of all the products of bits/digits with their respective place-weight constants.

    Examples:

    (i) Convert binary 11001101to decimal:

    The bit on the far right side is called the Least Significant Bit (LSB), because it stands in

    the place of the lowest weight (the one's place). The bit on the far left side is called the

    Most Significant Bit (MSB), because it stands in the place of the highest weight (the one

    hundred twenty-eight's place). Remember, a bit value of "1" means that the respective

    place weight gets added to the total value, and a bit value of "0" means that the respective

    place weight does not get added to the total value. With the above example, we have:

    Five)Hundred(Two205

    )14864128(

    )112041811603206411281(

    )2120212120202121(

    )partfractionalno()11001101(

    part)FractionalpartInteger(

    10

    10

    10

    01234567

    2

    r

    (ii) Convert binary 101.011 to decimal:

  • 6

    )FiveSeventyHundredThreepointFive(375.5

    )125.025.014(

    )125.0125.015.00112041(

    )212120212021(

    )011.101(

    part)FractionalpartInteger(

    10

    10

    10

    321012

    2

    r

    *(direct method for fractional part 0.011: decimal value/23=3/8=0.375)

    (iii) Convert octal 26.11 to decimal:

    )FiveSeventyHundredThreepointFive(375.5

    )125.025.014(

    )015625.01125.011682(

    )81818682(

    )11.26(

    part)FractionalpartInteger(

    10

    10

    10

    2101

    8

    r

    1.3.2 Useful Equivalent for Any number system to decimal: Wheneverany number system consists of only higher bit/digit, we can find its decimal

    equivalent by using the formula:

    ,1numberDecimal nr where r is the base and n is the member of bits/digits

    Examples:

    (i) Convert binary 111 to decimal:

    718)12(numberDecimal 103

    (ii) Convert octal 77 to decimal:

    63)18(numberDecimal 102

    (iii) Convert Quinary 44 to decimal:

    24)15(numberDecimal 102

    1.3.3 Decimal to any number system: To convert any decimal number system to its any number equivalent, decimal number is

    repeatedly divide by radix, and the remainder after each division is used to indicate the

    coefficient of that number to be formed in the case of integer first remainder is the Least

    Significant bit/ digit and multiplying by radix and recording any carriers in the integers

    position in case of fraction first carriers in the integers is the Least Significant bit/ digit.

    Examples:

    (i) Convert decimal l0.10 to binary: a. Integer part:

    2 10 Remainder

    2 5 0 LSB

    2 2 1

    2 1 0

    0 1 MSB

    b. Fractional part: Fractional part Integer part

    0.10 x2 = 0.20; 0.20 with carry of 0 MSB

    0.20 x2 = 0.40; 0.40 0

  • 7

    0.40 x2 = 0.80; 0.80 0

    0.80 x2 = 1.60; 0.60 1

    0.60 x2 = 1.40; 0.40 1 Repeat

    0.40 x2 = 0.80; 0.80 0 LSB

    (10.10)10= (1010.00110)2

    (ii) Convert decimal l0.10 to Octal: a. Integer part:

    8 10 Remainder

    8 1 2 LSB

    0 1 MSB

    b. Fractional part: Fractional part Integer part

    0.10 x8 = 0.80; 0.80 with carry of 0 MSB

    0.80 x8 = 6.40; 0.40 6

    0.40 x8 = 3.20; 0.20 3

    0.20 x8 = 1.60; 0.60 1

    0.60 x8 = 4.80; 0.80 4 Repeat

    0.80 x8 = 6.40; 0.40 6 LSB

    (10.10)10= (12.063146)8

    (iii) Convert decimal l0.10 to Hexadecimal: a. Integer part:

    16 10 Remainder

    0 A LSB

    b. Fractional part:

    Fractional part Integer part

    0.10 x16 = 1.60; 0.60 with carry of 1 MSB

    0.60 x16 = 9.60; 0.60 9

    0.60 x16 = 9.60; 0.60 9 Repeat

    (10.10)10= (A.19)16

    (iv) Convert decimal l0.10 to binary to Quinary: a. Integer part:

    5 10 Remainder

    5 2 0 LSB

    0 2 MSB

    b. Fractional part: Fractional part Integer part

    0.10 x5 = 0.50; 0.80 with carry of 0 MSB

    0.50 x5 = 2.50; 2.50 2

    0.50 x5 = 2.50; 2.50 2 Repeat

  • 8

    (10.10)10= (12.063146)8

    1.3.4 Binary to whose base in the power of 2 and vice versa: Use binary-power of 2methods, in this method the binary bits are grouped into groups of

    (power of 2) on each side of the binary point with zero added on either side if needed to

    complete a group of power of 2. Then each group of power of 2 bits is converted to its

    power of 2equivalents (2 bits- Quaternary; 3 bits- Octal: 4 bits-Hexadecimal etc).

    Since Quaternary, Octal, Hexadecimal is the second, third, and fourthpower of two

    (binary base), we can convert each digit of Quaternary, Octal, and Hexadecimal into its

    two, three, and four bit binary equivalent.

    a. Binary to octal and vice versa: Use binary-triple method, in this method the binary bits are grouped into groups of three

    on each side of the binary point with zero added on either side if needed to complete a

    group of three. Then each group of three bits is converted to its octal equivalent.

    Since eight (octal base) is the third power of two (binary base), we can convert each digit

    of octal into its three bit binary equivalent.

    To illustrate:

    (i) Convert binary l0.10 to octal: Binary Grouping Octal

    10.10 010.010 2.2

    (ii) Convert octal 2.2 to binary: ctal Grouping Binary

    2.2 010.010 010.010

    b. Binary to Hexadecimal and vice versa: Binary number is easily accomplished by partitioning the binary number into group of

    four bits starting from the binary point to left (integer part) and right (fractional part)

    directly converted to Hexadecimal. It may be necessary to add zeros to the left group; if it

    does not end in exactly four bits. Then each group of four bits is converted to its

    hexadecimal.

    Similarly hexadecimal to binary: Since sixteen (hexadecimal base) is the fourth power of

    two (binary base), we can convert each hexadecimal digit of into its four bit binary

    equivalent.

    Examples:

    (iii) Convert Binary l0.10 to hexadecimal:

    Binary Grouping Hexadecimal

    10.10 0010.0010 2.2

    (iv) Convert hexadecimal to l0.10 to binary: Hexadecimal Grouping Binary

    2.2 0010.0010 0010.0010

    1.3.5 Hexadecimal to Octal and vice versa:

  • 9

    1.4.4(b)) para above (seelHexadecima1.4.4(a)) para above (seeBinary Octal

    1.4.4(a)) para above (seeOctal1.4.4(b)) para above (seeBinary lHexadecima

    1.3.6 Hexadecimal to Binary and vice versa:

    1.4.5) para above (seelHexadecima1.4.4) para above (seeBinary

    1.4.5) para above (seeBinary lHexadecima

    1.4 Negative numbers:

    There are two types of binary numbers Unsigned and Signed Numbers can be represented

    in the following manner:

    bn-1 b1 b0

    Magnitude

    MSB

    (a) Unsigned number bn-1 bn-2 b1 b0

    Magnitude

    Sign bit MSB

    0 denotes + 1 denotes -

    (b) Signed number

    1.5.1 Unsigned binary number: The input data which does not include (+) or (-) signs

    and represents only the magnitude of the corresponding decimal number is called

    unsigned binary number. Smallest 8-bit unsigned number is 00H00 0000 0000 decimal and largest 8-bit unsigned number is 255FFH 1111 1111 decimal. We can add and subtract unsigned binary numbers provided certain conditions are satisfied.

    For an n-bit unsigned binary number, all n bits are used to represent the magnitude of the

    number. Unsigned Binary Numbers cannot represent negative numbers. For an n-bit

    binary number its decimal equivalent varies in the following relation:

    0

  • 10

    210

    210

    210

    )100100()36(

    10011)((19)

    10001)((17)

    The answer(100100)2 interpreted with the sixth bit as the 25place, is actually equal to -28

    (ones compliment), not +36 as we should get with +17 and +19 added together! Obviously, this is not correct.

    General rule for detecting overflow when adding two n-bit numbers using either One's

    Complement or Two's Complement Addition. An overflow occurs when the addition of

    two positive numbers results in a negative value or the addition of two negative numbers

    results in a positive value cannot occur when adding a positive number and a negative

    number.

    1.5.2 Signed binary number: Since digital computer and calculators handle positive as

    well as negative numbers, some means is required for representing the sign of the number

    (+ or ). This is usually done by placing another bit called sign bit to the left of the

    magnitude bit. Sign bit including magnitude is called sign - magnitude number. Sign

    magnitude numbers have limited use because they require complicated arithmetic circuit.

    For an n-bit/digit signed number, n-1 bits/digits are used to represent the magnitude of

    the number; the leftmost bit (MSB/MSD) is, generally, used to indicate the sign of the

    number. The sign bit can be represented as; lower number for positive number and higher number for negative number. But the magnitude of signed binary numbers can be represented in the following three ways.

    1. Signed-Magnitude representation

    2. Signed - (r-1)'s Complement representation

    3. Signed - r's complement representation

    In signed-magnitude, - (any number) is obtained from + (any number) by changing the

    sign bit in the leftmost position from low number to higher number. In Signed (r-1)'s Complement,- (any number) is obtained by (r-1)'s Complement of any number including

    the sign bit/digit.In Signed (r)'s Complement,- (any number) is obtained by (r)'s

    Complement of any number including the sign bit/digit.

    Table 5 lists all possible four bit signed binary number in the three representations.

    Decimal Signed-2s Complement

    Signed-1s Complement

    Signed

    Magnitude

    +7 0111 0111 0111

    +6 0110 0110 0110

    +5 0101 0101 0101

    +4 0100 0100 0100

    +3 0011 0011 0011

    +2 0010 0010 0010

    +1 0001 0001 0001

    +0 0000 0000 0000

    -0 - 1111 1000

    -1 1111 1110 10001

    -2 1110 1101 10010

    -3 1101 1100 10011

    -4 1100 1011 10100

  • 11

    -5 1011 1010 10101

    -6 1010 1001 10110

    -7 1001 1000 10111

    -8 1000 - -

    Table 5: Signed Binary Number Table 6 lists all possible four bit signed octal number in the three representations.

    Decimal Signed-8s Complement

    Signed-7s Complement

    Signed

    Magnitude

    +7 07 07 07

    +6 06 06 06

    +5 05 05 05

    +4 04 04 04

    +3 03 03 03

    +2 02 02 02

    +1 01 01 01

    +0 00 00 00

    -0 - 77 70

    -1 77 76 71

    -2 76 75 72

    -3 75 74 73

    -4 74 73 74

    -5 73 72 75

    -6 72 71 76

    -7 71 70 77

    -8 70 - -

    Table 6: Signed octal Number

    Table 7 lists all possible four bit signed decimal number in the three

    representations

    Decimal Signed-10s Complement

    Signed-9s Complement

    Signed

    Magnitude

    +7 07 07 07

    +6 06 06 06

    +5 05 05 05

    +4 04 04 04

    +3 03 03 03

    +2 02 02 02

    +1 01 01 01

    +0 00 00 00

    -0 - 99 90

    -1 99 98 91

    -2 98 97 92

    -3 97 96 93

    -4 96 95 94

    -5 95 94 95

  • 12

    -6 94 93 96

    -7 93 92 97

    -8 92 - -

    Table 7: Signed Decimal Number 1.5.2a Sign-and-Magnitude Representation.

    For an n-bit signed binary number, the MSB (leftmost bit) is the sign bit and the

    remaining n-1 bits represent the magnitude.

    - (2n-1 - 1)

  • 13

    1.5.2c rs Complement Representation An n-bit positive number (P) is represented in the same way as in the Sign-and-

    Magnitude representation.The sign bit (MSB) = 0.The remaining n-1 bits represent the

    magnitude.An n-bit negative number (N) is represented using the r's Complement of the equivalent positive number (P).

    rs complement of any number can be represented as.

    1P-)-mr-n(rcomplimentsr'

    Where n is the number of integer digit and m number of fraction digit. If the number

    having only integer part then the rs compliment of that number can be represented as:

    P-nr1P-1)-n(rcompliment sr'

    Table 10, shows the rules for subtraction by addition methods using negative number in

    (r-1)s / rs Complement form.

    compliments Carry No carry

    (r-1)s compliment Called End Around Carry, added to the LSB of the sum

    output. Answer is positive.

    Answer is negative with

    (r-1)s compliment of the sum output.

    rs compliment Ignore carry. Answer is positive.

    Answer is negative with

    rs compliment of the sum output.

    Table 10:(r-1)s / rs Complement Subtraction

    1.5 Binary arithmetic: In this lesson, we'll explore the techniques used to perform simple arithmetic functions on

    binary numbers, since these techniques will be employed in the design of electronic

    circuits to do the same. You might take longhand addition and subtraction for granted,

    having used a calculator for so long, but deep inside that calculator's circuitry all those

    operations are performed "longhand," using binary numeration. To understand how that's

    accomplished, we need to review to the basics of arithmetic.

    1.6.1 Binary Addition:

    Adding binary numbers is a very simple task, and very similar to the longhand addition of

    decimal numbers. As with decimal numbers, you start by adding the bits (digits) one

    column, or place weight, at a time, from right to left. Unlike decimal addition, there is

    little to memorize in the way of rules for the addition of binary bits:

    Inputs Outputs

    augend addend carry sum

    0 0 0 0

    0 1 1 0

    1 0 1 0

    1 1 0 1

    Table 8: Binary addition Consider the following examples:

    (10001)2

    + (10011)2

    (100100)2

  • 14

    The addition problem on the left did not require any bits to be carried, since the sum of

    bits in each column was 1 or 0, not 10 or 11. In the other two problems, there definitely

    were bits to be carried, but the process of addition is still quite simple.

    1.6.2 Binary Subtraction:

    As we'll see later, there are ways that electronic circuits can be built to perform this very

    task of addition, by representing each bit of each binary number as a voltage signal

    (either "high," for a 1; or "low" for a 0). This is the very foundation of all the arithmetic

    which modern digital computers perform.

    With addition being easily accomplished, we can perform the operation of subtraction

    with the same technique simply by making one of the numbers negative.

    Inputs Outputs

    minuend subtrahend borrow difference

    0 0 0 0

    0 1 1 1

    1 0 1 0

    1 1 0 0

    Table 9: Binary subtraction For example, the subtraction problem of 7 - 5 is essentially the same as the addition

    problem 7 + (-5). Since we already know how to represent positive numbers in binary, all

    we need to know now is how to represent their negative counterparts and we'll be able to

    subtract.

    Explanations

    A = 6 =110 We starts from LSB: substrate 1 from 0

    = 1 difference and 1 borrow. Taking borrow:

    Next two bit 11 becomes to 10.Again,

    Subtract 0 from 0 = 0difference and 0

    borrow.Last, MSB Subtract 0 from 0 =

    0difference and 0 borrow.

    -B = -5 = 101

    Result = (001)2 Verified

    1.6.2a Two's Complement Subtraction

    A B = A + (-B) Subtraction can be implemented using addition.Determine the Two's Complement

    representation for the negative number -B.Use Two's Complement Addition to add A and

    -B.

    (i)Carry:

    A = 6 =110 Explanations

    -B = -5 = 011 *[2s compliment of 101 = 1s compliment of 101+1 =010+1=011]

    Result = (1001)2 (1001)2

    {Ignore carry: answer is positive} Answer = + 001

    (ii) No carry:

    A = 5 =101 Explanations

  • 15

    -B = -6 =010 *[2s compliment of 110 = 1s compliment of 110+1 =001+1=010]

    Result = (111)2 = (111)2

    {no carry: Negative answer}with

    [2s compliment of 111 =000+1=001]

    Answer = - 001

    1.6.2b One's Complement Subtraction

    Instead of discarding the carry from the sign position (MSB), it must be added to the least

    significant bit (LSB) of the n-bit sum. Referred to as an end-around carry(EAC)..

    Following table summarizes the compliments arithmetic:

    (i)Carry:

    A = 6 =110 Explanations

    -B = -5 =010 For negative number:

    *[1s compliment of 101 = 010]

    Result = (1000)2 =(1000)2

    {EAC, add carry to LSD} Answer = + 001

    (ii) No carry:

    A = 5 =101 Explanations

    -B = -6 =001 For negative number:

    *[1s compliment of 110 = 001]

    Result = (110)2 = (110)2

    {no carry-Answer is negative}with [1s compliment of 110:

    = 001]

    Answer = - 001

    1.6 Octal arithmetic: Because binary numeration requires so many bits to represent relatively small numbers

    compared to the economy of the decimal system, analyzing the numerical states inside of

    digital electronic circuitry can be a tedious task. Computer programmers who design

    sequences of number codes instructing a computer what to do would have a very difficult

    task if they were forced to work with nothing but long strings of 1's and 0's, the "native

    language" of any digital circuit. To make it easier for human engineers, technicians, and

    programmers to "speak" this language of the digital world, other systems of place-

    weighted numeration have been made which are very easy to convert to and from binary.

    One of those numeration systems is called octal, because it is a place-weighted system

    with a base of eight. We wont discuss this base system in this document; rather we will concentrate on the hexadecimal system.

    1.7.1 Octal Addition:

    Adding octal numbers is a very simple task, and very similar to the longhand addition of

    decimal numbers. As with decimal numbers, you start by adding the bits (digits) one

    column, or place weight, at a time, from right to left. Unlike decimal addition, there is

    little to memorize in the way of rules for the addition of binary bits:

  • 16

    Inputs Outputs

    augend addend carry octal sum

    0 0 0 0

    0 1 0 1

    1 2 0 3

    2 3 0 5

    3 4 0 7

    4 5 1 1

    5 6 1 3

    6 7 1 5

    Table 11: Octal addition Just as with decimal addition, when the sum in one column is a two-digit number, the

    least significant figure is written as part of the total sum and the most significant figure is

    "carried" to the next left column. Consider the following examples:

    0ctal decimal Explanations

    (456)8

    302

    We start from LSD: add 6 to 3 =(9) 10= (11)8

    = octal sum=1 with carry 1.

    Add this carry to next digit

    = previous carry (1) +5 + 2= (8)10= (10)8 = octal sum =0 with carry 1. Last digit MSD

    = previous carry (1) + 4+ 1= 6

    (+123)8

    +83

    Result (601)8 = 385 Verified

    1.7.2 OctalSubtraction:

    As we'll see later, there are ways that electronic circuits can be built to perform this very

    task of addition, by representing each digit of each octal number as a voltage signal.

    Inputs Outputs

    minuend subtrahend borrow difference

    0 0 0 0

    0 1 8 1

    1 2 8 7

    2 3 8 7

    3 4 8 7

    4 5 8 7

    5 6 8 7

    6 7 8 7

    2 1 8 9

    3 2 0 1

    4 2 0 2

    5 2 0 3

    6 1 0 5

    7 1 0 6

    Table 12: Octal Subtraction With addition being easily accomplished, we can perform the operation of subtraction

    with the same technique simply by making one of the numbers negative For example, the

    subtraction problem of 7 - 5 is essentially the same as the addition problem 7 + (-5).

  • 17

    Since we already know how to represent positive numbers in binary, all we need to know

    now is how to represent their negative counterparts and we'll be able to subtract.

    0ctal decimal Explanations

    (75)8

    61

    We start from LSD: substrate 6 from 5

    (cannot substrate) take borrow fromnext

    digit (8+5= 15, subtract 6 from 15= 7).

    Next digit7 becomes to 6.Again, Subtract 6

    from 6 = 0 difference and 0 borrow.

    (-66)8

    -54

    Result (7)8 = 7

    1.7.2a Eight 's Complement Subtraction

    A B = A + (-B) Subtraction can be implemented using addition.Determine the Two's Complement

    representation for the negative number -B.Use Eight's Complement Addition to add A

    and -B.

    (i)Carry:

    A = 6 =6 Explanations

    -B = -5 =3* *[8s compliment of 5 = 81-5=(3)8]

    Result = (9)10 =(11)8

    {Ignore carry} Answer = +1

    (ii) No carry:

    A = 5 =5 Explanations

    -B = -6 =2* *[8s compliment of 5 = 81-6=(2)8]

    Result = (7)10 = (7)8 {no carry means negative

    answer}with

    [8s compliment of 7 = 81-7=(1)8] Answer = -1

    1.7.2b Seventh's Complement Subtraction

    Instead of discarding the carry from the sign position (MSB), it must be added to the least

    significant bit (LSB) of the n-bit sum. Referred to as an end-around carry(EAC).

    (i)Carry:

    A = 6 =6 Explanations

    -B = -5 =2* For negative number:

    [7s compliment of 5 = (81-1)-5=(2)8]

    Result = (8)8 =(10)8

    {EAC, add carry to LSD} Answer = +1

    (ii) No carry:

    A = 5 =5 Explanations

    -B = -6 =1* For negative number:

  • 18

    *[7s compliment of 6 = (81-1)-6=(1)8]

    Result = (6)8 = (6)8

    {no carry-Answer is negative}with

    [7s compliment of E: = (81-1)-6 = (1)16]

    Answer = -1

    1.7 Decimal arithmetic: the representation of signed decimal number in BCD is similar to the representation of signed number in binary

    1.8.1 Decimal Addition:

    Adding decimal numbers is a very simple task, and very similar to the longhand addition

    of decimal numbers. As with decimal numbers, you start by adding the digits one

    column, or place weight, at a time, from right to left. Unlike decimal addition, there is

    little to memorize in the way of rules for the addition of binary bits:

    decimal Explanations

    327

    We start from LSD: add 3 to 7 = (10) 10

    = decimal sum=0 with carry 1.

    Add this carry to next digit

    = previous carry (1) +8 + 2= (11)10 =decimal sum=1 with carry 1. Last digit MSD

    = previous carry (1) + 2+ 3= (6)10

    +283

    Result = 610

    Just as with decimal addition, when the sum in one column is a two-digit number, the

    least significant figure is written as part of the total sum and the most significant figure is

    "carried" to the next left column. Consider the following examples: In the other two

    problems, there definitely were bits to be carried, but the process of addition is still quite

    simple.

    1.8.2 DecimalSubtraction:

    As we'll see later, there are ways that electronic circuits can be built to perform this very

    task of addition, by representing each bit of each binary number as a voltage signal

    (either "high," for a 1; or "low" for a 0). This is the very foundation of all the arithmetic

    which modern digital computers perform.

    With addition being easily accomplished, we can perform the operation of subtraction

    with the same technique simply by making one of the numbers negative.

    For example, the subtraction problem of 7 - 5 is essentially the same as the addition

    problem 7 + (-5). Since we already know how to represent positive numbers in binary, all

    we need to know now is how to represent their negative counterparts and we'll be able to

    subtract.

    Usually we represent a negative decimal number by placing a minus sign directly to the

    left of the most significant digit, just as in the example above, with -5.

    1.8.2a Ten's Complement Subtraction

    A B = A + (-B) Subtraction can be implemented using addition. Determine the Two's Complement

    representation for the negative number -B. Use Ten's Complement Addition to add A and

    -B.

  • 19

    (i)Carry:

    A = 6 =6 Explanations

    -B = -5 =5* *[10s compliment of 5 = 101-5= (5)10]

    Result = (11)10 =(11)1o

    {Ignore carry} Answer = +1

    (ii) No carry:

    A = 5 =5 Explanations

    -B = -6 =4* *[10s compliment of 6 = 101-6=(4)10]

    Result = (9)10 = (9)10 {no carry: Answer will negative}with

    [10s compliment of 9 = 101-9=(1)16] Answer = -1

    1.8.2b Nine's Complement Subtraction

    Instead of discarding the carry from the sign position (MSB), it must be added to the least

    significant bit (LSB) of the n-bit sum. Referred to as an end-around carry.

    (i)Carry:

    A = 6 =6 Explanations

    -B = -5 =4* For negative number:

    *[9s compliment of 5 = (101-1)-5=(4)10]

    Result = (10)10 =(10)10

    {EAC, add carry to LSD} Answer = +1

    (ii) No carry:

    A = 5 =5 Explanations

    -B = -6 =3* For negative number:

    *[9s compliment of 6 = (101-1)-6=(3)10]

    Result = (8)10 = (8)10

    {no carry: negative answer}with

    [9s compliment of 8: = (101-1)-8 = (1)10]

    Answer = -1

    1.8 Hexadecimal Arithmetic:

    The hexadecimal system is a place-weighted system with a base of sixteen. Valid ciphers

    include the normal decimal symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, plus six alphabetical

    characters A, B, C, D, E, and F, to make a total of sixteen. As you might have guessed

    already, each place weight differs from the one before it by a factor of sixteen.

    1.9.1 Hexadecimal Addition:

    Adding hexadecimal numbers is not a very simple task, and very similar to the longhand

    addition of octal numbers. As with decimal numbers, you start by adding the digit one

  • 20

    column, or place weight, at a time, from right to left. Unlike decimal addition, there is

    little to memorize in the way of rules for the addition of binary bits:

    Inputs Outputs

    augend Addend carry octal sum

    0 0 0 0

    0 1 0 1

    1 2 0 3

    2 3 0 5

    3 4 0 7

    4 5 1 1

    5 6 1 3

    6 7 1 5

    Table 13: Hexadecimal addition Just as with decimal addition, when the sum in one column is a two-bit (two-digit)

    number, the least significant figure is written as part of the total sum and the most

    significant figure is "carried" to the next left column. Consider the following examples:

    Hexadecimal decimal Explanations

    (26)16

    38

    We start from LSD: add 6 to 3 = (9) 10= (9)16

    = hexadecimal sum=9 with carry 0.

    Add this carry to next digit

    = previous carry (0) +2 + 2= (4)10= (4)16

    (+23)16

    +35

    Result (49)16 = 73 Verified

    1.9.2 HexadecimalSubtraction:

    As we'll see later, there are ways that electronic circuits can be built to perform this very

    task of addition, by representing each bit of each binary number as a voltage signal

    (either "high," for a 1; or "low" for a 0). This is the very foundation of all the arithmetic

    which modern digital computers perform.

    With addition being easily accomplished, we can perform the operation of subtraction

    with the same technique simply by making one of the numbers negative.

    Inputs Outputs

    Minuend subtrahend borrow difference

    0 0 0 0

    0 1 F 1

    1 2 F

    2 3 F

    3 4 F

    4 5 F

    5 6 F

    6 7 F

    2 1 F

    3 2 0 1

    4 2 0 2

    5 2 0 3

    6 1 0 5

  • 21

    7 1 0 6

    Table 14: Signed octal Number For example, the subtraction problem of 7 - 5 is essentially the same as the addition

    problem 7 + (-5). Since we already know how to represent positive numbers in binary, all

    we need to know now is how to represent their negative counterparts and we'll be able to

    subtract.

    Usually we represent a negative decimal number by placing a minus sign directly to the

    left of the most significant digit, just as in the example above, with -5. However, the

    whole purpose of using binary notation is for constructing on/off circuits that can

    represent bit values in terms of voltage (2 alternative values: either "high" or "low"). In

    this context, we don't have the luxury of a third symbol such as a "minus" sign, since

    these circuits can only be on or off (two possible states). One solution is to reserve a bit

    (circuit) that does nothing but represent the mathematical sign:

    Hexadecimal decimal Explanations

    (22)16

    34

    We start from LSD: substrate 3 from 2

    (cannot substrate) take borrow from next

    digit (16+2= 18, subtract 3 from 18= 15).

    Next digit 2 becomes to 1.Again, Subtract

    1 from 1 = 0 difference and 0 borrow.

    (-13)16

    -19

    Result (F)16 = 15 Verified

    1.9.2a Sixteen's Complement Subtraction

    A B = A + (-B) Subtraction can be implemented using addition.Determine the Two's Complement

    representation for the negative number -B.Use Sixteen's Complement Addition to add A

    and -B.

    (i)Carry:

    A = 6 =6 Explanations

    -B = -5 =11* [16s compliment of 5 = 161-5=(11)16]

    Result = (17)1 =(11)16

    {Ignore carry} Answer = +1

    (ii) No carry:

    A = 5 =5 Explanations

    -B = -6 =10* *[16s compliment of 5 = 161-5=(11)16]

    Result = (15)10 = (F)16 {Carry-Ans. Negative}with

    [16s compliment of F = 161-15=(1)16] Answer = -1

    Answer = -1

    1.9.2b Fifteen's Complement Subtraction

    Instead of discarding the carry from the sign position (MSB), it must be added to the least

    significant bit (LSB) of the n-bit sum. Referred to as an end-around carry.

  • 22

    (i)Carry:

    A = 6 =6 Explanations

    -B = -5 =10* [15s compliment of 5 = (161-1)-5=(11)16]

    Result = (16)10 =(10)16

    {EAC, add carry to LSD} Answer = +1

    (ii) No carry:

    A = 5 =5 Explanations

    -B = -6 =9* *[15s compliment of 5 = 161-5=(11)16]

    Result = (14)1 = (E)16

    {no carry-Answer is negative}with

    [15s compliment of E: = (161-1)-14 = (1)16]

    Answer = -1

    1.9 Binary codes Computers work with binary numbers. The signals in most present-day electronic digital

    systems use just two discrete values and are therefore said to be binary. A binary digit,

    called bit, has two values: 0 and 1. Each coefficient is multiplied by 2n where n is the

    position of bit. Discrete elements of information are represented with groups of bits

    called binary codes. The binary system is a different number system. The binary number

    is a string of zeros and ones. Since it has only two digits, the base is 2.

    An n-bit binary code is a group of n bits that assumes up to 2n distinct combinations of

    1s and 0s, with each combination representing one element of the set that is being coded. A set of four elements can be coded with two-bits, with each element assigned one

    of the following bit combinations: 00, 01, 10, and 11. A set of eight elements requires a

    three-bit code and a set of 16 elements requires a four-bit code.

    Although the minimum number of bits required to code 2n distinct quantities is n, there is

    no maximum number of bits that may be used for a binary code. For example, the 10

    decimal digit can be coded with 10 bits, and each decimal digit can be assigned a bit

    combination of nine 0s and 1. In this particular binary code, the digit 6 is assigned the bit combination 0001000000.

    In binary system the positive and negative numbers may be represented as (i) signed

    magnitude, and (ii) 1s complement and 2s complement. In order to represent the 16 decimal digits, 0 through 15, in binary code, it is necessary to

    use at least 4-bit binary numbers (0 = 0000 and 15 = 1111). Since there are sixteen

    combinations of four binary digits, it is possible to form a very large number of distinct

    codes.

    There are of two types of binary code namely Weighted and Unweighted. A weighted

    code is one in which each position in the code has a specific weight. Aunweighted code is

    one in which the positions in the code do not have a specific weight. Lets assume a 4-bit weighted code havingWeights: w3, w2, w1, w0and Code: a3a2a1a0 their Decimal (D)

    equivalent:

    D = a3 x w3 + a2 x w2 + a1 x w1 + a0 x w0

    1.9.1 Binary Coded Decimal (BCD) or 8421 code:

  • 23

    It is a 4-bit binary number weighted code used to represent each decimal digit.

    The binary values from 0000 to 1001 are valid code used to represent the decimal

    digits 0 to 9. The binary values 1010 to 1111 are invalid not used (unused).

    1.9.2 2-4-2-1 Code Weighted code with w3 = 2, w2 = 4, w1 = 2, w0 = 1

    1.9.3 Excess-3 Code Obtained from the 8-4-2-1 (weighted code).

    Add 3 (00112) to each of the codes.

    1.9.4 2-out-of-5 Code Unweighted code

    Exactly 2 of the 5 bits are 1 for each valid code. Following tables summarizes the different binary codes.

    Four Different Binary Codes for the Decimal Digit

    Decimal Digit BCD 8421 2421 Excess-3 8,4,-2,-1

    0 0000 0000 0011 0000

    1 0001 0001 0100 0111

    2 0010 0010 0101 0110

    3 0011 0011 0110 0101

    4 0100 0100 0111 0100

    5 0101 1011 1000 1011

    6 0110 1100 1001 1010

    7 0111 1101 1010 1001

    8 1000 1110 1011 1000

    9 1001 1111 1100 1111

    Unused bit

    combinations

    1010 0101 0000 0001

    1011 0110 0001 0010

    1100 0111 0010 0011

    1101 1000 1101 1100

    1110 1001 1110 1101

    1111 1010 1111 1110

    2 Table 15: Different binaryCodes

    1.10.4 Gray Code(s) Unweighted code, Code values for successive decimal digits differ in exactly one

    bit.

    Decimal 3-bit Gray Code 4-bit Gray Code

    G2 G1 G0 G3 G2 G1 G0

    0 0 0 0 0 0 0 0

    1 0 0 1 0 0 0 1

    2 0 1 1 0 0 1 1

    3 0 1 0 0 0 1 0

    4 1 1 0 0 1 1 0

    5 1 1 1 0 1 1 1

    6 1 0 1 0 1 0 1

    7 1 0 0 0 1 0 0

  • 24

    8 1 1 0 0

    9 1 1 0 1

    10 1 1 1 1

    11 1 1 1 0

    12 1 0 1 0

    13 1 0 1 1

    14 1 0 0 1

    15 1 0 0 0

    Table 16: 3-bit, 4-bit Gray Code

    1.10.5 ASCII Code American Standard Code for Information Interchange. Common code used for the

    storage and transfer of alphanumeric characters. 7-bit Weighted Code. Can

    represent a total of 128 characters.Used to represent letters, numbers and other

    characters (e.g. special control characters). Any word or number can be

    represented (and stored or transferred) using its ASCII Code.

    Table 17: American Standard Code for Information Interchange (ASCII)

    b4b3b2b1 b7b6b5

    000 001 010 011 100 101 110 111

    0000 NUL DLE SP 0 @ P ` p

    0001 SOH DC1 ! 1 A Q A q

    0010 STX DC2 2 B R B r 0011 ETX DC3 # 3 C S C s

    0100 EOT DC4 $ 4 D T D t

    0101 ENQ NAK % 5 E U E u

    0110 ACK SYN & 6 F V F v

    0111 BEL EDP 7 G W G w 1000 BS CAN ( 8 H X H x

    1001 HT EM ) 9 I Y I y

    1010 LF SUB * : J Z J z

    1011 VT ESC + ; K [ K {

    1100 FF FS , < L \ L |

    1101 CR GS - = M ] M }

    1110 SO RS . > N ^ N ~

    1111 SI US / ? O - O DEL

    Control Character:

    NUL Null DLE Data-link escape

    SOH Start of heading DC1 Device control 1

    STX Start of text DC2 Device control 2

    ETX End of text DC3 Device control 3

    EOT End of transmission DC4 Device control 4

    ENQ Enquiry NAK Negative acknowledge

    ACK Acknowledge SYN Synchronous idle

    BEL Bell EDP End-of-transmission block

    BS Backspace CAN Cancel

    HT Horizontal tab EM End of medium

  • 25

    LF Line feed SUB Substitute

    VT Vertical tab ESC Escape

    FF Form feed FS File separator

    CR Carriage return GS Group separator

    SO Shift out RS Record separator

    SI Shift in US Unit separator

    SP Space DEL Delete

    1.10.6 Error correcting and detecting codes:

    It is physically impossible for any data recording or transmission medium to be

    100% perfect 100% of the time over its entire expected useful life.As more bits

    are packed onto a square centimeter of disk storage, as communications

    transmission speeds increase, the likelihood of error increases-- sometimes

    geometrically.Thus, error detection and correction is critical to accurate data

    transmission, storage and retrieval.

    Data that is either transmitted over communication channel (e.g. bus) or stored in

    memory is not completely error free.Thus, to provide data integrity over the long

    term, error correcting codes are required.

    Hamming codes and Reed-Soloman codes are two important error correcting

    codes.

    Reed-Soloman codes are particularly useful in correcting burst errors that occur

    when a series of adjacent bits are damaged.Because CD-ROMs are easily

    scratched, they employ a type of Reed-Soloman error correction. Because the

    mathematics of Hamming codes is much simpler than Reed-Soloman, we discuss

    Hamming codes in detail.Hamming codes are code words formed by adding

    redundant check bits, or parity bits, to a data word.Error can cause by:

    1.10.6a Transmission Errors:Signal distortion or attenuatione.g. sender and

    receiver out of synchronous, can happen if clocks are not synchronized systems distributed over network

    1.10.6b Storage Errors:DRAM memory cell contents can change spuriously due

    to some Electromagnetic interference n magnetic storage devices such as disks,

    magnetic flux density ncreases could cause one or more bits to flip (change that

    value)Error detection is the ability to detect errors. Error correction has an

    additional feature that enables identification and correction of the errors. Error

    detection always precedes error correction. Both can be achieved by having extra

    or redundant or check bits in addition to data deduce that there is an error. Original

    Data is encoded with the redundant bit(s). New data formed is known as code

    wordParity

    1.10.6c the simplest and oldest error detection method:

    In this scheme, a binary digit called parity is used to indicate whether the number

    of bits with value of one in a given set of bits is even or odd and is appended to

    original data. Usually used to detect transmission error.The sender adds the parity

    bit to existing data bits before transmission.The receiver checks for the expected

    parity, if wrong parity found, the received data is discarded and retransmission is

    requested

    Parity type: Even

  • 26

    Forced an even number of ones on total data sent000 0001 (total number of 1 is 1

    i.e., odd) add 1 in the MSB 1 000 0001 to make it even. Generating even parity bit is just an XOR function.

    Check Data Received Examples 01111111 - incorrect, 1000 0000 incorrect,1000 0001 - valid

    Note that error could be in data or parity Not entirely fool proof

    Parity type: Odd

    Forced an odd number of ones000 0001 (total number of 1 is 1 i.e., odd) add 0 in the MSB 0000 0001 to make it odd. Odd parity is generated using a XNOR

    function.

    Limitations of Parity

    Data Word Parity Code

    (Even)

    Code word

    00 0 000

    01 1 011

    10 1 101

    11 0 110

    Two data and one parity (3 bit) 8 possible combinations, only 4 correct code-

    words, Cannot determine which bit position has a problem. If 001 is encountered,

    it is not a valid code-word and hence error is detected. The correct code-word

    could either be 101 or 011 but we cannot tell

    000 100

    001 101

    010 110

    011 111

    What happens if the code word is subjected to two-bit error?E.g. 011 became 000

    while transmission. According to parity scheme, no error is detected but error!!

    In general, if an odd number of bits (including the parity bit) are changed from a

    set of bits then parity bit will be incorrect and will thus indicate that an error has

    occurred

    1.10.7 Hamming Code (HC):

    Hamming Code is type of Error Correcting Code (ECC), provides error detection

    and correction mechanism. Adopt parity concept, but have more than one parity

    bit. In general hamming code is code word of n bits with mdata bits and r parity (or check bits)i.e. n = m + r, can detect {D (min) 1} error, and correct

    2

    1)(MinDerrors. Hence to correct k errors, need D (min) = 2k + 1, you need a

    least a distance of 3 to correct a single bit error.Thus, a Hamming distance of 2k +

    1 is required to be able to correct k errors in any data word.

    Hamming distance is provided by adding a suitable number of parity bits to a data

    word. It is well known for its single-bit error detection and correction capability.

    Its based on the adding of r parity (redundancy) bits to m data bus such that: 2rm + r + 1, 2r-1 bits: hammingCode, r: parity (redundancy) bits, (2r-1) - r: data

  • 27

    bits. After error detection and correction, if any, the data bits have to be

    reassembled by removing the redundancy bits.

    Hamming code is normally used for transmission of 7-bit data item. Scaling it for

    larger data lengths results in a lot of overhead due to interspersing the parity bits

    and their removal later.

    Hamming Distance and Error Detection: The Hamming distance between two

    code words is the number of bits in which two code words differ.This pair of

    bytes has a Hamming distance 3:

    Hamming Distance is equal to the number of bit positions in which two code

    words differ or XOR of this pair of bytes then count total numbers of 1 is the

    Hamming distance. The minimum Hamming distance for a code is the smallest

    Hamming distance between all pairs of words in the code.The minimum

    Hamming distance for a code, D(min), determines its error detecting and error

    correcting capability.

    Suppose we have a set of n-bit code words consisting of m data bits and r

    (redundant) parity bits.

    An error could occur in any of the n bits, so each code word can be associated

    with n erroneous words at a Hamming distance of 1. For example 10001001 and

    10110001 have distance of 3,

    If hamming distance is d apart, then d-single bit errors are required to convert any

    one valid code into another. Implying that this error would not be detected.

    In previous parity example (slide 7), Could detect 1-bit error as 4 code words had

    hamming distance = 2, But could not detect 2-bit error.

    In general, to detect k-single bit error, minimum hamming distance D(min) =k + 1

    Hence we need code words that have D(min) = 2 + 1 = 3 to detect 2-bit errors. If

    there is a larger hamming distance between valid code words, then we may be

    able to determine which valid codeword was intended. Suppose a code needs just

    2 different values, and we use:One valid value = 0000 0000 and the other = 1111

    1111. Then distance between these is 8.

    Suppose we got 2 bit changes so that:0000 0000 became 0011 0000, Can we

    determine what the transmitted value was?Was it more likely 0000 0000 or 1111

    1111?

    The greater the distance between valid code words, the easier it is to figure what

    the correct codeword was requires additional redundant bits (> 1 parity bit) to

    choose code words that are far apartD (min) = 2k + 1 is required for correcting k-

    errors.

    Determining number of Parity bits for single-bit correction: Hamming Code

    for single-bit error correction is the most commonly usedExperiments (IBM

    study) show 98% time there are single-bit errors, Need determine r for m-data bits

    that provides code words of n-bits that has single-bit correction capabilities.

    An error could occur in any of the n bits of the code word, so each code word can

    be associated with erroneous words (at a hamming distance of 1)E.g. Previous

    Parity Example (slide 7)

  • 28

    000 can become 001 or 010 or 100 due to single bit errorTherefore, we have n + 1

    bit patterns for each code word: one valid code word, and n erroneous words. This

    gives us the inequality: (n + 1) 2 m 2n where 2 m is the number of legal code

    Hamming Code: Determining Parity bits for single-bit correction

    Because n = m + r, we can rewrite the inequality as:

    (m + r + 1) 2 m 2 m+ ror (m + r + 1) 2r This inequality gives us a lower limit on the number of parity bits that we need in

    our code words.

    Example: Suppose we have data words of length m = 4

    (4 + r + 1) 2r Implies that r must be greater than or equal to 3. This means to build a code with

    4-bit data words that will correct single-bit errors; we must add 3 check bits.

    Example: Generation of 12-bit Code word

    Number of parity bits: if the number of information bits is designated m then the

    number of parity bits, r is determines by the following relationship:

    (m + r + 1) 2 m 2 m + r

    Or (m + r + 1) 2 r 8-bit data needs 4 parity bits, total of 12-bit code word, using our code words of

    length 12, number each bit position starting with 1 in the low-order bit. Each bit

    position corresponding to an even power of 2 will be occupied by a parity or

    check bit. All other bit positions are for the data to be encoded. This means to

    build a code with 8-bit data words that will correct single-bit errors, we must add

    4 check bits, creating code words of length 12.

    T

    T

    a

    b

    l

    e

    1

    8

    :

    Placement of the parity bits in the code

    The parity bits are located in the positions that are numbered corresponding to

    ascending powers of two.Notice that the binary position number of parity bit P1

    has 1 for its column. This parity bit checks all bit positions including itself, that

    have 1s in the same location (column) in the binary position numbers. Therefore, Parity Bit P1checks the bit positions: 1, 3, 5, 7, 9, and 11.

    Parity Bit P2checks the bit positions: 2, 3, 6, 7, 10, and 11.

    Bit Designation Bit Position Binary Position Number

    P8 (23) P4 (22) P2 (21) P1 (20)

    P1 1 0 0 0 1

    P2 2 0 0 1 0

    D3 3 0 0 1 1

    P4 4 0 1 0 0

    D5 5 0 1 0 1 D6 6 0 1 1 0

    D7 7 0 1 1 1

    P8 8 1 0 0 0

    D9 9 1 0 0 1 D10 10 1 0 1 0

    D11 11 1 0 1 1 D12 12 1 1 0 0

  • 29

    Parity Bit P4checks the bit positions: 4, 5, 6, 7, and 12.

    Parity Bit P8checks the bit positions: 8, 9, 10, 11, and 12.

    Each parity bit calculates the parity for some of the bits in the code word

    Error Correcting Codes (ECC) in General

    Hamming Code is type of ECC,Others include Reed-Solomon, Convolution Code

    Requires extra bits for maintaining information integrity E.g. in hamming code: 3 bits are added to a 4-bit data

    The overhead of extra bits does pay off Single-bit correction often costs less than sending the entiredata twice

    If the storage is the only source of data (e.g. disk or DRAM) then we want a error-

    correction to avoid crashing of programs

    1.11 Industrial application of number system and code

  • 30

    Number system at a glance

    There are two input signals: analog signals have infinite number of distinct values and are continuous,

    while digital signals have finite number of distinct values and are discrete in nature.

    Types of number systems are : decimal, binary, octal, hexadecimal.

    Codes are representation if digital in specified format which include symbols, alphabets etc.

    There are two logic levels in digital system : high (1) and low (0).

    There are two logic systems positive and negative.

    Number system is a set of rules and symbols to represent numbers. It can be weighted or non-

    weighted.

    Number of values that a character or digit can assume is called Radix or Base.

    Decimal system has radix 10. Leftmost digit is MSD and rightmost digit is LSD. Binary system has radix 2 and two binary digits one 1 and 0. Its weight is expressed as a power

    of 2.

    The smallest unit of information is called bit (0 and 1).

    Binary representation of four bits is called a Nibble.

    A byte is a combination of 8-binary bits.

    A word is a combination of 16-binary bits.

    Octal numbers system has radix 8 and the digits are (0 to 7). Its weight is expressed in power of 8. Hexadecimal has radix 16. The digits are 0 to 9 in continuation with letters A to F Its weight is

    expressed in power of 16.

    ls complement of a binary number is written by simply replacing all 0s by 1 and all 1s by 0. 2s complement is one increment of ls complement. Numbers without +ve / -ve sign are unsigned numbers.

    Numbers represented by sign magnitude are signed numbers.

    BCD represent as 4 bit binary code; also known as 8421 code.

    Gray codes are reflected codes in which the successive coded characters differ in only bit position.

    Alphanumeric codes are represented by letters, symbols and numbers. These are ABC codes,

    EBCDIC codes and ASCII code.

  • 31

    Problems

    1.1.1 What is number system? What are its types? Give example for each type of number system. 1.1.2 Convert the binary number (110)2 to its decimal equivalent. 1.1.3 Convert the binary number (1011.01) to its decimal equivalent. 1.1.4 Convert the following:

    (521.63)8 to the base 10 and vice versa.

    (11011.111)2 to the base 10 and vice versa.

    (2B.48)16 to the base 10 and vice versa.

    (0.6875)10 to the base 2 and vice versa.

    (305.6875)10 to the base 8 and vice versa.

    (7825.760) 10 to the base 16 and vice versa.

    (0.1011011) 2 to the base 8 and vice versa.

    (10110110.101111001)2 to the base 16 and vice versa.

    (436) 8 to the base 16 and vice versa.

    (1AF)16 to the base 8 and vice versa.

    (68.4B) 16 to the base 8 and vice versa.

    1.1.5 What is the largest decimal number that can be represented by a 16 bit binary word? 1.1.6 Define bit, byte and nibble.

    1.1.7 Find the complement of DCCBBA . 1.1.8 What do you mean by weighted code? Give example. 1.1.9 Represent the decimal number 8620 in BCD and as a binary number. 1.1.10 List the advantages of octal over hexadecimal number system. 1.1.11 What is the use of (r-1)s and rs compliment in digital electronics? What do you think about

    (r-n)s compliment where n = 2, 3, 4, 5, 6, 7, 8, 9? 1.1.12 Find twos complement of the numbers (i) 01001110 ; (ii) 01100100. 1.1.13 What is the need to study octal and hexadecimal system, when the Digital machine

    understands only binary code?

    1.1.14 Where do we use ASCII, Excess-3 and Gray codes? 1.1.15 Determine the decimal representation of a negative integer whose 8-bit twos complement

    code is 10010110.

    1.1.16 Give the binary code for the hexadecimal number AEO. 1.1.17 How negative numbers are accounted for in digital system? 1.1.18 Give the binary code for the hexadecimal number F01. 1.1.19 Determine the decimal representation of a negative integer whose 8bit twos complement

    code 10010110.

    1.1.20 Subtract the following numbers using different techniques. (i) (1100.10)2 (111.01)2 (ii) (10001.01)2 (1111.11)2

    1.1.21 Add the following numbers in Excess - 3 Code. (i) 108 + 789

    (ii) 275 + 496

    1.1.22 Subtract the following numbers (i) (BC5)16 (A2B)16 (ii) (1 75.6)8 (47.7)8

    1.1.23 Add the following numbers in BCD (i) 89.6 + 273.7

    (ii) 205.7 + 193.65

    1.1.24 How will you detect overflow in signed magnitude and 2s complement integer additions? 1.1.25 What are the applications of hexadecimal system? Perform the following conversions

    (a) (225225) 10 into hexadecimal number.

    (b) (10011.1101)2 into hexadecimal number.

  • 32

    1.1.26 What is the importance and applications of Gray code? Convert the binary number 10100111 to Gray code.

    1.1.27 Represent the decimal numbers (a) 27, (b) 396 and (c) 4096 in binary form in (i) ASCII code, (ii) Gray code and (iii) Excess 3 code.

    1.1.28 If A = 1101 and B = 101 find: (ii) A + B (iii) A - B (iv) B - A (v) A x B By 2s complement method.

    1.1.29 Find the difference (6C1-1DA) in the hexadecimal system. Check your result converting all number, i.e. the given two numbers and the result obtained from subtraction to the decimal

    system.

    1.1.30 In the following expression, find the value of radii x ( x is the positive integer) (212)x= (23)10 (1000)x=[(11)2]3

    1.1.31 A particular brand of CD player has the capacity of converting 12-bit signals from a CD into their equivalent analog values.

    What are the largest and smallest hex value that can be used in this CD system.

    How many different analog values can be represented by this system?

    1.1.32 Typically, digital thermometer use BCD to drive their displays (a) How many BCD bits are required to drive a 3-digit thermometer display? (b) What 12 bits are sent to be the display for a temperature of 147?

    1.1.33 In a new number system, A and B are successive digits such that (AB)x=25, and (BA)x=31. Find A, B, and x.

    [{A=3,B=4, and x=7} hints: successive digit means B=A+1]

    1.1.34 Instead of using digits0 and 1 for the binary numbers, use A and B, respectively. Show how to count from 0 to 7.

    [{A, B, BA, BB, BAA, BAB, BBA, BBB} hints: ignore MSB 0] 1.1.35 Show how to count a number system with a base 3, use x, y, z instead of 0, 1, 2. 1.1.36 The solution to the quadratic equation x2-11x+22=0 is x=3 and 6. What is the base of the

    number?

    1.1.37 Construct addition and multiplication tables for base 3. 1.1.38 Nothing that 32=9, formulate a simple procedure for converting base-3 number directly to

    base 9 using (21 10 20 11 02 22)3 to base 9.

    1.1.39 Consider the following four codes

    Code A Code B Code C Code D 0001 000 01011 000000 0010 001 01100 001111 0100 011 10010 110011 1000 010 10101

    110

    111

    101

    100

    Note: Minimum distance=2: detect single bit error.

    Minimum distance = 3: detect double bit error (detect and correct one single error).

    Minimum distance=4: detect triple bit error (detect double error and correct single

    error).

    (a) Which of the following properties is satisfied by each of the above codes? (i) Detect single errors. [ A,C,D hints: detect single error-minimum distance=2]

  • 33

    (ii) Detect double errors[ C, and D hints: minimum distance=3, 4] (iii) Detect triple error[ D hints: detect minimum distance=4] (iv) Correct single errors[C, and D hints: minimum distance= 3, 4] (v) Correct double errors[ None hints: minimum distance must be =5] (vi) Correct single and detect double errors[ D hints: minimum distance=4]

    (b) How many words can be added to code A without changing its error-detection and correction capabilities? Give possible set of such words. Is this set unique?

    [Hints: there are four possible code words that can be added to code A, without

    changing it error-detection and correction capability. Those are 1101, 0111, 1011 and

    1110. This set is unique.]

    1.1.40 Assign a binary code in some orderly manner to the 52 playing cards. Use minimum number of bits. [ hints: 25=32, 26=64, we need 6 bit]

    1.1.41 Find the decimal number whose complement twos complement is 10000000. 1.1.42 Determine the base of the numbers in each case for the following operation to be correct.

    (a) 52

    14 , (b) 1.12

    20

    302 , (c) 541

    1.1.43 In the following series, the same integer is expressed in different number systems. Determine the missing number of the series.

    10000, 121, 100, ? , 24, 22, 20

    Table 2: Different Number SystemBut in nature, Binary, octal, decimal and hexadecimal is most commonly used number system.1. Binary System:In the binary system, there are only two symbols or possible digit values, 0 and 1. This base-2 system can be used to represent any quantity that can be represented in decimal or other base system.2. Decimal System:In the decimal system, there are ten symbols or possible digit values, 0 to 9. This base-10 system can be used to represent any quantity that can be represented in binary or other base system.3. Octal System:The octal number system has a base of eight, meaning that it has eight possible digits: 0, 1,2,3,4,5,6,7.4. Hexadecimal System:The hexadecimal system uses base 16. Thus, it has 16 possible digit symbols. It uses the digits 0 through 9 plus the letters A, B, C, D, E, and F as the 16 digit symbols.General rule for representing any number system (base r) by using positional notation is as follows:Computers work with binary numbers. The signals in most present-day electronic digital systems use just two discrete values and are therefore said to be binary. A binary digit, called bit, has two values: 0 and 1. Each coefficient is multiplied by 2n ...An n-bit binary code is a group of n bits that assumes up to 2n distinct combinations of 1s and 0s, with each combination representing one element of the set that is being coded. A set of four elements can be coded with two-bits, with each element a...Although the minimum number of bits required to code 2n distinct quantities is n, there is no maximum number of bits that may be used for a binary code. For example, the 10 decimal digit can be coded with 10 bits, and each decimal digit can be assigne...In binary system the positive and negative numbers may be represented as (i) signed magnitude, and (ii) 1s complement and 2s complement.In order to represent the 16 decimal digits, 0 through 15, in binary code, it is necessary to use at least 4-bit binary numbers (0 = 0000 and 15 = 1111). Since there are sixteen combinations of four binary digits, it is possible to form a very large n...