unit i - potharajuvidyasagar.files.wordpress.com · boolean algebra , basic theorems and...

58
Vignana Bharathi Institute of Technology UNIT 1 DLD potharajuvidyasagar.wordpress.com P VIDYA SAGAR DLD UNIT – I Digital Systems: Binary Numbers, Octal, Hexa Decimal and other base numbers, Number base conversions, complements, signed binary numbers, Floating point number representation, binary codes, error detecting and correcting codes, digital logic gates(AND, NAND,OR,NOR, Ex-OR, Ex-NOR), Boolean algebra , basic theorems and properties, Boolean functions, canonical and standard forms. VIDYA SAGAR P

Upload: others

Post on 19-Oct-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    DLD

    UNIT – I Digital Systems: Binary Numbers,

    Octal, Hexa Decimal and other base

    numbers, Number base

    conversions, complements, signed

    binary numbers, Floating point

    number representation, binary codes,

    error detecting and correcting codes,

    digital logic gates(AND,

    NAND,OR,NOR, Ex-OR, Ex-NOR),

    Boolean algebra , basic theorems and

    properties, Boolean functions,

    canonical and standard forms.

    VIDYA SAGAR P

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Number Systems :

    A number system is a representation method for numbers, A number system is

    identified by its base ,The base is a decimal unsigned integer with a minimum value of

    2,The is no limit on the maximum value for the base, however, the largest known base

    is 16,Commonly used number systems are also identified by their name

    There are 4 commonly used number systems:

    Decimal base 10

    Hexadecimal base 16

    Octal base 8

    Binary base 2

    The base determines the range of a digit in the number system which starts with

    0 and ends with base-1

    For bases with range exceeding 10, the A-Z alpha symbols are used to represent

    values greater than 9

    Examples

    Base 10 digit range is 0 – 9

    Base 5 digit range is 0 - 4

    Base 16 digit range is 0 – 9 and A – F

    Computers internally stores and process data using the binary system

    Binary is compatible with the computer hardware architecture which is based on

    Boolean digital logic

    Binary is base 2 with a digit range of 0 - 1

    A binary digit is also known as bit

    Most computers use the hexadecimal or the octal number systems in

    programming and debugging

    Hexadecimal is also known as hex

    Hex is base 16 with a digit range of 0 – 9, A – F

    Octal is base 8 with a digit range of 0 – 7

    Advantages

    Both number systems can be used as a short hand notation for binary

    More readable than binary and hence easier for humans to work with

    Easy to convert into and from binary

    Humans on the other hand, work with the decimal system, Conversion between

    binary and decimal is necessary to make human to machine interaction possible,

    Conversion between the different number systems is also possible, Conversion does not

    change the magnitude of the number

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Counting in Different Bases :

    Counting is the process of repeatedly adding 1 to the number

    Going through a complete digit range, exhausting all possible

    combinations

    Shift to the left one place

    Repeat as necessary until the number is completely represented Theoretically, the counting process can continue indefinitely, However, there is

    always a limit on the available digits to store a number (storage size),Therefore,

    counting process will stop when all the available digits are exhausted, Overflow will

    occur when storage size limit is exceeded

    The following table shows a count in hexadecimal, decimal, octal, and binary

    Hexadecimal Decimal Octal Binary

    0 0 0 0

    1 1 1 1

    2 2 2 10

    3 3 3 11

    4 4 4 100

    5 5 5 101

    6 6 6 110

    7 7 7 111

    8 8 10 1000

    9 9 11 1001

    A 10 12 1010

    B 11 13 1011

    C 12 14 1100

    D 13 15 1101

    E 14 16 1110

    F 15 17 1111

    10 16 20 10000

    Range Calculations :

    The range of a number that can be represented is determined by:

    Storage size number of digits

    Base of the number system used to represent the number

    Range can be computed as: (result in decimal)

    R = Bn (R = Range, B = Base, n = number of digits)

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Examples:

    8 binary bits range 28 = 25610

    3 decimal digits range 103 = 100010

    3 digits in hex range 163 = 409610

    Binary range calculations is often required in computers

    Examples :

    Integer number data unit range with storage size of 16 bits = 216 = 65536

    Memory addressing capability MAR size of 32 bits = 232 = 4GB

    Range can also be computed as the product of its sub-ranges

    32 binary bits range 210 X 210 X 210 X 22 = 1K X 1K X 1K X 4 = 4G

    12 binary bits range 210 X 22 = 1K X 4 = 4K

    Integer Digit Weight Calculations :

    A digit weight is computed as: (result is always in decimal)

    W = Bn (W = Weight, B = base, n = digit position)

    Digit position numbering starts from the least significant digit and ends with the

    most significant digit

    Digit position starts at 0 and ends with the number of digits – 1

    Examples:

    4-digit decimal weight calculation 103, 102, 101, 100 = 100010, 10010, 1010, 110

    4-bit binary weight calculation 23, 22, 21, 20 = 810, 410, 210, 110

    4-digit octal weight calculation 83, 82, 81, 80 = 51210, 6410, 810, 110

    Note: that any base power 0 = 1

    Each digit has n times the weight of its next rightmost neighbor (where n is the base)

    In binary each digit has twice the weight of its next right neighbor

    In decimal each digit has 10 times the weight of its next rightmost neighbor

    Convert between related bases :

    Two number systems are related when one number system base is an integral power of

    the other

    A single digit in the larger base requires n digits in the smaller base (where n is the

    power value)

    Octal is related to binary since it takes 3 binary digits to represent 1 octal digit (23 = 8)

    Hex is related to binary since it takes 4 binary digits to represent 1 hex digit (24 = 16)

    Hex and octal, however, are not related

    Conversion between related number systems is direct

    Use a trial and error method to determine if two bases are related

    Smaller base power 2, 3, 4, and so on…

    If result = larger base, then the two bases are related

    If result exceed larger base, then the two bases are not related

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Examples :

    1. Are 2 and 16 related?

    22 = 4

    23 = 8

    24 = 16 base 2 and 16 are related

    2. Are 3 and 8 related?

    32 = 9 base 3 and 8 are not related

    Smaller base to larger base conversion method :

    Determine the n value

    Construct a conversion table (i.e. counting table as seen above is an example of

    conversion table)

    Group the number into groups of n digits

    Must start grouping from the right (i.e. least significant digit)

    Pad with zeros if last group is less than n digits

    Group by group, perform direct conversion using the conversion table

    Examples :

    Convert 110101110110002 to hex

    4 binary digits are required to represent a single hex digit (i.e. n = 4)

    Refer to the conversion table above

    Group the number into groups of 4 digits: 11 0101 1101 1000

    Pad last group with zeros: 0011 0101 1101 1000

    Convert each group to their equivalent hex digit = 35D816

    Convert 110101110110002 to octal

    3 binary digits are required to represent a single octal digit (i.e. n = 3)

    Refer to the conversion table above

    Group the number into groups of 3 digits: 11 010 111 011 000

    Pad last group with zeros: 011 010 111 011 000

    Convert each group to their equivalent octal digit = 327308

    Convert 110101110110002 to base 4

    2 binary digits are required to represent a single base 4 digit (i.e. n = 2)

    Construct a conversion table

    Base 4 Binary

    0 00

    1 01

    2 10

    3 11

    Group the number into groups of 2 digits: 11 01 01 11 01 10 00

    Convert each group to their equivalent hex digit = 311312016

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Larger base to Smaller base conversion :

    Determine the n value

    Construct a conversion table (i.e. counting table as seen above)

    Digit by digit, perform direct conversion using the conversion table

    Notes: don’t miss padding leading zeros to fill the n digits in the smaller base

    Examples

    Convert 35D816 to binary

    Each hex digit requires 4 binary digits (i.e. n = 4)

    Refer to the conversion table above

    Map each digit to its equivalent binary digits

    = 0011 0101 1101 10002

    Convert 2753318 to binary

    Each octal digit requires 3 binary digits (i.e. n = 3)

    Refer to the conversion table above

    Map each digit to its equivalent binary digits

    = 010 111 101 011 011 0012

    Convert 212234 to binary

    Each base 4 digit requires 2 binary digits (i.e. n = 2)

    Refer to the base 4 to binary conversion table above

    Map each digit to its equivalent binary digits

    = 10 01 10 10 112 Convert between non decimal and non related number systems :

    It is impractical to directly convert between none decimal number systems that

    are not related

    Decimal can be used as an intermediary conversion base

    As well, a base that is related to both bases can be used as an intermediary

    conversion base

    Binary can be used as an intermediate conversion base to convert between hex and

    octal

    Examples :

    Convert 35D816 to octal (note that the two bases are none decimal and are not

    related)

    Convert the number to binary = 00110101110110002

    Convert the binary result to octal = 011 010 111 011 000

    = 327302

    Convert 21203 to base 5 (note that the two bases are none decimal and are not related)

    There is no intermediate base that is related to both bases so we use decimal as an

    intermediate base

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Convert the number to decimal = 0 x 30 + 2 x 31 + 1 x 32 + 2 x 33 = 6910

    Convert the decimal result to base 5 = 2345

    = 2345

    Fraction conversion:

    Fraction number conversion does not always result in an accurate result due to:

    Representation of a fraction number that is possible in one base may be impossible

    to represent in another base

    If precise conversion cannot be done, conversion will result in lose of accuracy (i.e.

    lose of significant digits)

    Examples:

    0.110 is impossible to represent in binary (0.0001100110011…)

    0.13 is impossible to represent in decimal (0.333333…)

    When converting a number that contains both integer and fraction parts

    The two parts must be converted separately

    The fraction point must remain at its original location

    Number base conversions:

    Decimal to any base conversion Steps :

    Step 1 − Divide the decimal number to be converted by the value of the new base.

    Step 2 − Get the remainder from Step 1 as the rightmost digit (Least Significant

    Digit) of new base number.

    Step 3 − Divide the quotient of the previous divide by the new base.

    Step 4 − Record the remainder from Step 3 as the next digit (to the left) of the new

    base number.

    Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes

    zero in Step 3.

    The last remainder thus obtained will be the Most Significant Digit (MSD) of the new

    base number.

    Examples:

    Decimal to Binary:

    Two methods: There are reverse processes of the two methods used to convert a binary

    no. to a decimal no.

    I method: is for small no’s The values of various powers of 2 need to be remembered

    for conversion of larger no’s have a table of powers of 2 known as the sum of weights

    method. The set of binary weight values whose sum is equal to the decimal no. is

    determined.

    • To convert a given decimal integer no. to binary,

    (1). Obtain largest decimal no. which is power of 2 not exceeding the remainder & record

    it

    (2). Subtract this no. from the given no & obtain the remainder

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    (3). Once again obtain largest decimal no. which is power of 2 not exceeding this

    remainder & record it.

    (4). Subtract through no. from the remainder to obtain the next remainder.

    (5). Repeat till you get a ―0‖ remainder

    The sum of these powers of 2 expressed in binary is the binary equivalent of the original

    decimal no. similarly to convert fractions to binary.

    II method: It converts decimal integer no. to binary integer no by successive division

    by 2 & the decimal fraction is converted to binary fraction by double –dabble method.

    Example: 163.87510 binary

    Given decimal no. is mixed no.So convert its integer & fraction parts separately.

    Integer part is 16310

    The largest no. which is a power of 2, not exceeding 163 is 128.

    128=27 =100000002

    remainder is 163-128=35

    The largest no., a power of 2, not exceeding 35 is 32. 32=25=1000002, Remainder is 35-32=3 The largest no., a power of 2, not exceeding 35is 2. 2=21 =102, Remainder is 3-2=1 1=20= 12

    16310= 100000002+1000002+102+12= 101000112.

    The fraction part is 0.87510 1. The largest fraction, which is a power of 2, not exceeding 0.875 is 0.5

    0.5=2-1=0.1002, Remainder is 0.875-.5=0.3752. 2. 0.375 is 0.25

    0.25 =2-2=0.012, Remainder is 0.375-.25=0.125. 3. 0.125 is 0.125 itself

    0.125 =2-3 =0.0012 0.87510=0.1002+0.012+0.0012=0.1112 Final result is 163.87510 =10100011.1112.

    Here is an example of using double – dabble method to convert 1792 decimal to binary:

    Decimal Number Operation Quotient Remainder Binary Result

    1792 ÷ 2 = 896 0 0

    896 ÷ 2 = 448 0 00

    448 ÷ 2 = 224 0 000

    224 ÷ 2 = 112 0 0000

    112 ÷ 2 = 56 0 00000

    56 ÷ 2 = 28 0 000000

    28 ÷ 2 = 14 0 0000000

    14 ÷ 2 = 7 0 00000000

    7 ÷ 2 = 3 1 100000000

    3 ÷ 2 = 1 1 1100000000

    1 ÷ 2 = 0 1 11100000000

    0 done.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Decimal to Octal

    Here is an example of using repeated division to convert 1792 decimal to octal:

    Decimal Number Operation Quotient Remainder Octal Result

    1792 ÷ 8 = 224 0 0

    224 ÷ 8 = 28 0 00

    28 ÷ 8 = 3 4 400

    3 ÷ 8 = 0 3 3400

    0 done.

    Decimal to Hexadecimal

    Here is an example of using repeated division to convert 1792 decimal to hexadecimal:

    Decimal Number Operation Quotient Remainder Hexadecimal Result

    1792 ÷ 16 = 112 0 0

    112 ÷ 16 = 7 0 00

    7 ÷ 16 = 0 7 700

    0 done.

    The only addition to the algorithm when converting from decimal to hexadecimal is that

    a table must be used to obtain the hexadecimal digit if the remainder is greater than

    decimal 9.

    Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    Hexadecimal: 0 1 2 3 4 5 6 7 8 9 A B C D E F

    The addition of letters can make for funny hexadecimal values. For example, 48879

    decimal converted to hex is:

    Decimal Number Operation Quotient Remainder Hexadecimal Result

    48879 ÷ 16 = 3054 15 F

    3054 ÷ 16 = 190 14 EF

    190 ÷ 16 = 11 14 EEF

    11 ÷ 16 = 0 11 BEEF

    0 done.

    MORE EXAMPLES: Convert 612410 to base 5

    New Base From Base Number Remainder

    5 6124 4 least significant digit

    5 1224 4

    5 244 4

    5 48 3

    5 9 4 ↑

    5 1 1 most significant digit

    0 = 1434445

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Convert 815110 to hexadecimal

    New Base From Base Number Remainder

    16 8151 7 least significant digit

    16 509 13

    16 31 15 ↑

    16 1 1 most significant digit

    0 = 1FD716

    Convert 6410 to binary

    New Base From Base Number Remainder

    2 64 0 least significant digit

    2 32 0

    2 16 0

    2 8 0

    2 4 0

    2 2 0 ↑

    2 1 1 most significant digit

    0 = 10000002

    Binary to any base conversion Steps:

    Binary to Decimal: A method to convert from binary to decimal. This method involves addition and

    multiplication.

    1. Start the decimal result at 0.

    2. Remove the most significant binary digit (leftmost) and add it to the result.

    3. If all binary digits have been removed, you’re done. Stop.

    4. Otherwise, multiply the result by 2.

    5. Go to step 2.

    Here is an example of converting 11100000000 binary to decimal:

    Binary Digits Operation Decimal Result Operation Decimal Result

    11100000000 +1 1 × 2 2

    1100000000 +1 3 × 2 6

    100000000 +1 7 × 2 14

    00000000 +0 14 × 2 28

    0000000 +0 28 × 2 56

    000000 +0 56 × 2 112

    00000 +0 112 × 2 224

    0000 +0 224 × 2 448

    000 +0 448 × 2 896

    00 +0 896 × 2 1792

    0 +0 1792 Done.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Binary to Octal: An easy way to convert from binary to octal is to group binary digits into sets of three,

    starting with the least significant (rightmost) digits.

    Binary: 11100101 = 11 100 101

    011 100 101 Pad the most significant digits with zeros if necessary to complete a group of three.

    Then, look up each group in a table:

    Binary: 000 001 010 011 100 101 110 111

    Octal: 0 1 2 3 4 5 6 7

    Binary = 011 100 101

    Octal = 3 4 5 = 345 oct

    Binary to Hexadecimal: An equally easy way to convert from binary to hexadecimal is to group binary digits into sets of four, starting with the least significant (rightmost) digits.

    Binary: 11100101 = 1110 0101

    Then, look up each group in a table:

    Octal to any base conversion Steps:

    Octal to Binary:

    Converting from octal to binary is as easy as converting from binary to octal. Simply

    look up each octal digit to obtain the equivalent group of three binary digits.

    Octal: 0 1 2 3 4 5 6 7

    Binary: 000 001 010 011 100 101 110 111

    Octal = 3 4 5

    Binary = 011 100 101 = 011100101 binary

    Octal to Hexadecimal :

    When converting from octal to hexadecimal, it is often easier to first convert the octal

    number into binary and then from binary into hexadecimal. For example, to convert 345

    octal into hex:

    (from the previous example)

    Octal = 3 4 5

    Binary = 011 100 101 = 011100101 binary

    Binary: 0000 0001 0010 0011 0100 0101 0110 0111

    Hexadecimal: 0 1 2 3 4 5 6 7

    Binary: 1000 1001 1010 1011 1100 1101 1110 1111

    Hexadecimal: 8 9 A B C D E F

    Binary = 1110 0101

    Hexadecimal = E 5 = E5 hex

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Drop any leading zeros or pad with leading zeros to get groups of four binary digits

    (bits): Binary 011100101 = 1110 0101

    Then, look up the groups in a table to convert to hexadecimal digits.

    Binary: 0000 0001 0010 0011 0100 0101 0110 0111

    Hexadecimal: 0 1 2 3 4 5 6 7

    Therefore, through a two-step conversion process, octal 345 equals binary 011100101 equals hexadecimal E5.

    Octal to Decimal :

    Converting octal to decimal can be done with repeated division.

    1. Start the decimal result at 0.

    2. Remove the most significant octal digit (leftmost) and add it to the result.

    3. If all octal digits have been removed, you’re done. Stop.

    4. Otherwise, multiply the result by 8.

    5. Go to step 2.

    Octal Digits Operation Decimal Result Operation Decimal Result

    345 +3 3 × 8 24

    45 +4 28 × 8 224

    5 +5 229 Done.

    The conversion can also be performed in the conventional mathematical way, by

    showing each digit place as an increasing power of 8.

    345 octal = (3 * 82) + (4 * 81) + (5 * 80) = (3 * 64) + (4 * 8) + (5 * 1) = 229 decimal.

    Hexadecimal to any base conversion Steps:

    Hexadecimal to Binary :

    Converting from hexadecimal to binary is as easy as converting from binary to

    hexadecimal. Simply look up each hexadecimal digit to obtain the equivalent group of

    four binary digits.

    Hexadecimal: 0 1 2 3 4 5 6 7

    Binary: 0000 0001 0010 0011 0100 0101 0110 0111

    Hexadecimal: 8 9 A B C D E F

    Binary: 1000 1001 1010 1011 1100 1101 1110 1111

    Hexadecimal = A 2 D E

    Binary = 1010 0010 1101 1110 = 1010001011011110 binary

    Binary: 1000 1001 1010 1011 1100 1101 1110 1111

    Hexadecimal: 8 9 A B C D E F

    Binary = 1110 0101

    Hexadecimal = E 5 = E5 hex

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Hexadecimal to Octal :

    When converting from hexadecimal to octal, it is often easier to first convert the

    hexadecimal number into binary and then from binary into octal. For example, to

    convert A2DE hex into octal:

    (from the previous example)

    Hexadecimal = A 2 D E

    Binary = 1010 0010 1101 1110 = 1010001011011110 binary

    Add leading zeros or remove leading zeros to group into sets of three binary digits.

    Binary: 1010001011011110 = 001 010 001 011 011 110

    Then, look up each group in a table:

    Binary: 000 001 010 011 100 101 110 111

    Octal: 0 1 2 3 4 5 6 7

    Binary = 001 010 001 011 011 110

    Octal = 1 2 1 3 3 6 = 121336 octal

    Therefore, through a two-step conversion process, hexadecimal A2DE equals binary

    1010001011011110 equals octal 121336.

    Hexadecimal to Decimal :

    Converting hexadecimal to decimal can be performed in the conventional mathematical

    way, by showing each digit place as an increasing power of 16. Of course, hexadecimal

    letter values need to be converted to decimal values before performing the math.

    Hexadecimal: 0 1 2 3 4 5 6 7 8 9 A B C D E F

    Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    A2DE hexadecimal:

    = ((A) * 163) + (2 * 162) + ((D) * 161) + ((E) * 160)

    = (10 * 163) + (2 * 162) + (13 * 161) + (14 * 160)

    = (10 * 4096) + (2 * 256) + (13 * 16) + (14 * 1)

    = 40960 + 512 + 208 + 14 = 41694 decimal

    Signed Number Representation:

    In general, we represent the positive (unsigned) numbers without any sign indication

    and negative numbers with ‘minus’ (negative sign) sign before them. But these are not

    applicable for computing in the digital systems like, computers, as the data is

    represented in binary number system. So to represent the sign a special notation is

    required.

    Positive Signed binary numbers

    The binary numbers having their MSB 0 are called “Positive signed binary numbers”.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Negative Signed binary numbers

    The binary numbers having their MSB 1 are called “Negative signed binary numbers”.

    Unsigned numbers can have a wide range of representation. But whereas, in case of

    signed numbers, we can represent their range only from – (2(n-1) – 1) to + (2(n-1) – 1).

    Where n is the number of bits (including sign bit).

    Ex: For a 5 bit signed binary number (including 4 magnitude bits & 1 sign bit), the

    range will be

    – (2(5-1) – 1) to + (2(5-1) – 1)

    -(2(4) – 1 ) to + (2(4) – 1)

    -15 to +15

    Unsigned 8- bit binary numbers will have range from 0-255. The 8 – bit signed binary

    number will have maximum and minimum values as shown below.

    The maximum positive number is 0111 1111 +127

    The maximum negative number is 1000 0000 -127

    There are 2 different methods used to represent signed integer in computers

    Sign-and-magnitude representation

    Complementary representation

    Sign-and-magnitude Representation

    8-bit sign-magnitude format

    Sign Magnitude

    7 6-0

    The sign is represented followed by the number magnitude

    A sign bit, typically the leftmost bit, (0 for +, 1 for -) is used to represent the sign

    The positive range is one-half of the range and the negative range is makes up the

    second half

    Example: 16-bit (1 bit sign and 15 bit magnitude) have a positive range of: +0 to

    +32767 and negative range of and -0 to –32767

    Note that the total range is the same but redistributed between the positive side and

    the negative side

    Disadvantage

    There are 2 different values for the zero (i.e. +0 and –0)

    The system must test at the end of every calculation to ensure the presence of a

    single 0,Calculations is very complex and difficult to implement in hardware (i.e. no

    consistent way of performing the calculations)

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Complementary Representation:

    Complementary representation is the prevalent method for representing signed integer

    in computers. Every number system has 2 forms of complementary representations

    Base (R-1)’s complement

    Base R’s complement

    2 forms of binary complementary representation

    1’s complement

    2’s complement

    2 forms of decimal complementary representation

    9’s complement

    10’s complement

    2 forms of hex complementary representation

    15’s complement

    16’s complement

    2 forms of octal complementary representation

    7’s complement

    8’s complement

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Advantage

    Provide sign free representation

    The sign of the number does not need special handling

    Calculations is simple and consistent for all different signed combination of numbers

    For simplicity let’s first start by studying the decimal complementary representation:

    9’s complement

    10’s complement

    9’s Complement Representation

    9’s complement is the decimal counter part of the binary 1’s complement

    Positive range matches the sign-and-magnitude representation positive range

    Negative range is different than the sign-and-magnitude representation negative range

    The sign of a number is determined by checking the most significant digit

    Positive when most significant digit values 0-4

    Negative when most significant digit values 5-9

    Convert from sign-and-magnitude to 9’s complement

    Must specify the number of 9’s complement storage digits available to represent the

    number

    If number is positive no conversion is necessary (i.e. same as sign-and-magnitude

    representation)

    Pad the number with 0’s, if needed, to represent all the assigned number of storage

    digits

    If number is negative conversion is required (complement the number)

    Complementary base – number

    The complementary base is the highest value in the number supported by the given

    number of digits

    Complementary base for:

    3 digits = 999

    5 digits = 99999

    Examples

    1. Represent –467 in 3-digit 9’s complement

    The number is negative so complement the number = 999 – 467 = 532

    2. Represent –467 in 4-digit 9’s complement

    The number is negative so complement the number = 9999 – 467 = 9532

    3. Represent 467 in 3-digit 9’s complement

    The number is positive so the 9’s complement is the same as the number = 467

    4. Represent 667 in 4-digit 9’s complement

    The number is positive so the 9’s complement is the same as the number

    Need to pad with zero to fill the entire storage space = 0667

    5. Represent 667 in 3-digit 9’s complement

    The number cannot be represented with only 3-digits (overflow occur)

    Maximum positive number the can be represent is 499

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Convert from 9’s complement to sign-and-magnitude

    Determine whether the number is positive or negative (inspect the most significant

    digit)

    If the number is positive, the sign-and-magnitude equivalent is the same as the 9’s

    complement

    If the number is negative, complement the number

    Complementary base – number

    Add the negative sign

    Examples

    1. Convert 9990 to sign-and-magnitude representation

    The number is negative (most significant digit is 9)

    Complement the number: 9999 – 9990 = 9

    Add negative sign -9

    2. Convert 595 to sign-and-magnitude representation

    The number is negative (most significant digit is 5)

    Complement the number: 999 – 595 = 404

    Add negative sign = -404

    3. Convert 4990 to sign-and-magnitude representation

    The number is positive (most significant digit is 4)

    The result is the same as the 9’s complement = 4990

    Addition and Subtraction Arithmetic (9’s complement)

    Addition in 9’s complement is done using the following method:

    Add the 2 numbers in the normal way

    Add 1 to the result if there is end-round carry

    An end-round carry occur if the result overflow the storage space

    Subtraction in 9’s complement is done using the following method:

    Complement any number with negative sign (i.e. eliminate the negative sign)

    Add the two numbers using the same method as the “Addition in 9’s

    Complement”

    Examples :

    Add (799 + 100)

    o 799 + 100 = 899

    Add (799 + 300)

    o 799 + 300 =(1)099

    o Add end-round carry = 1 + 099 = 100

    Add (0799 + 0300)

    o 0799 + 0300

    = 1099

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Subtract (799 – 100)

    o Find 9’s complement of 100 = 999 – 100 = 899

    o Add 799 + 899 = (1) 698

    o Add the end-round carry = 1 + 698 = 699

    Subtract (106 – 090)

    o Find 9’s complement of 90 = 999 – 90 = 909

    o Add 106 + 909 = (1)015

    o Add end-round carry = 1 + 015 = 016

    Subtract (0106 – 0090)

    o Find 9’s complement of 90 = 9999 – 90 = 9909

    o Add 0106 + 9909 = (1) 0015

    o Add end-round carry = 1 + 0015 = 0016

    Subtract (-40 - 2)

    o Find 9’s complement of 40 = 99 – 40 = 59

    o Find 9’s complement of 2 = 99 – 2 = 97

    o Add 59 + 97 = (1) 56

    o Add end-round carry = 1 + 56 = 57

    10’s Complement Representation

    The 10’s complement solves the dual zero problem in 9’s complement

    See Figure 4.11 in page 110 for 10’s complement representation of 3-digit

    decimal number

    10’s complement = 9’s complement + 1

    Convert from sign-and-magnitude to 10’s complement

    Similar to 9’s complement with the following differences

    Complementary base is 1 more than the 9’s complement (i.e. 9’s

    complement + 1)

    Examples

    Represent –467 in 3-digit 10’s complement

    The number is negative so complement the number = 1000 – 467 = 533

    Represent –467 in 4-digit 10’s complement

    The number is negative so complement the number = 10000 – 467 = 9533

    Represent 467 in 3-digit 10’s complement

    The number is positive so the 10’s complement is the same as the number = 467

    Represent 667 in 4-digit 10’s complement

    The number is positive so the 10’s complement is the same as the number = 0667

    Represent 667 in 3-digit 10’s complement

    The number cannot be represented with only 3-digits (overflow)

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Convert 10’s complement to sign-and-magnitude

    Similar to 9’s complement with the following differences

    Complementary base is 1 more than the 9’s complement (i.e. 9’s complement + 1)

    Examples

    1. Convert 9990 to sign-and-magnitude representation

    The number is negative (most significant digit is 9)

    Find 10’s complement = 10000 – 9990 = 10

    Add negative sign = -10

    Convert 595 to sign-and-magnitude representation

    The number is negative (most significant digit is 5)

    Complement the number: 1000 – 595 = 405

    Add negative sign = -405

    2. Convert 4990 to sign-and-magnitude representation

    o The number is positive (most significant digit is 4)

    o The result is the same as the 10’s complement = 4990

    Addition and Subtraction Arithmetic (10’s complement)

    Addition in 10’s complement is done using the following method:

    Add the two numbers

    Carry beyond the specified number of digits is dropped

    Subtraction in 10’s complement is done using the following method:

    Find the 10’s complement of any number with negative sign (i.e. eliminate the

    negative sign)

    Add using the same method as the “Addition in 10’s Complement”

    Examples

    1. Add (799 + 100)

    o 799 + 100 = 899

    2. Add (799 + 300)

    o 799 + 300 = (1)099

    o Drop the end-round carry = 099

    3. Add (0799 + 0300)

    o 0799 + 0300 = 1099

    4. Subtract (799 – 100)

    o Find the 10’s complement of 100 = 1000 – 100 = 900

    o Add 799 + 900 = (1) 699

    o Drop the end-round carry = 699

    5. Subtract (106 – 090)

    o Find the 10’s complement of 90 = 1000 – 90 = 910

    o Add 106 + 910 = (1) 016; Drop the end-round carry = 016

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    6. Subtract (0106 – 0090)

    o Find the 10’s complement of 0090 = 10000 – 90 = 9910

    o Add 0106 + 9910 = (1) 0016

    o Drop the end-round carry = 0016

    1’s Complement Representation

    1’s complement is a complementary representation method for representing signed

    integer in binary

    1’s complement is the counter part of 9’s complement in decimal

    See Figure 4.10 for illustration of 8-bit 1’s complement representation

    The sign of a number is determined by checking the most significant bit

    Positive when most significant bit is 0

    Negative when most significant bit is 1

    1’s complement is performed by inverting every bit (0 becomes 1 and 1 becomes 0)

    Find 1’s complement

    Pad the number with 0’s if needed to represent all the assigned number of

    storage bits

    Invert the bits

    Examples

    Find the 8-bit 1’s of the binary number 00101101

    Invert to find the 1’s complement

    = 11010010

    Find the 16-bit 1’s of the binary number 00101101

    Pad with 0’s to get 16-bit representation = 0000000000101101

    Invert to find the 1’s complement

    = 1111111111010010

    Convert from decimal sign-and-magnitude to 1’s complement

    Convert the decimal number to binary

    Pad with zeros to fill the entire storage space

    Determine whether the number is positive or negative

    If the number is positive, no need to complement the number

    If the number is negative, you need to complement the number

    Examples

    Convert –4510 to 8-bit 1’s complement

    Convert from decimal to binary = 101101

    Pad with 0’s to get 8-bit representation = 00101101

    The number is negative (the sign is -) so invert the bits

    = 11010010

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Convert 4510 to 16-bit 1’s complement

    Convert from decimal to binary = 101101

    Pad with 0’s to get 16-bit representation = 0000000000101101

    The number is positive so no need to complement

    = 0000000000101101

    Convert -2510 to 16-bit 1’s complement

    Convert from decimal to binary = 11001

    Pad with 0’s to get 16-bit representation = 0000000000011001

    The number is negative so invert the bits

    = 1111111111100110

    Convert from 1’s complement to decimal sign-and-magnitude

    Determine whether the number is positive or negative

    If the number is positive, no need to complement the number

    If the number is negative, you need to complement the number

    Convert to decimal

    Add the negative sign if the number is negative

    Examples

    Convert 00101101 to decimal sign-and-magnitude

    The number is positive (most significant bit is 0), no need to complement

    Convert to decimal = 45

    = 45

    Convert 11010010 to decimal sign-and-magnitude

    The number is negative (most significant bit is 1), then first find the

    complement of the number

    Find 1’s complement = 00101101

    Convert to decimal = 45

    Add the negative sign = -45

    Convert 1111111111100110 to decimal sign-and-magnitude

    The number is negative (most significant bit is 1), then first find the

    complement of the number

    Find 1’s complement = 0000000000011001

    Convert to decimal = 25

    Add the negative sign = -25

    Addition and Subtraction Arithmetic (1’s complement)

    Addition in 1’s complement is done using the following method

    Add the two numbers

    If there is an end-round carry, add the carry to the result

    Subtraction in 1’s complement is done using the following method

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Find 1’s complement of the number with negative sign in front (i.e. eliminate

    negative sign)

    Adding the two numbers

    Examples

    1. Add (00101101 + 00111010) (i.e. 45 + 58 = 103)

    00101101 + 00111010

    = 01100111 = 103 in decimal

    2. Add (01101010 + 11111101) (i.e. 106 - 2 = 104)

    01101010 + 11111101 = (1) 01100111

    Add end-carry to the result = 1 + 01100111

    = 01101000 = 104 in decimal

    3. Subtract (00101101 - 00111010) (i.e. 45 - 58 = -13)

    Find 1’s complement of the second number = 11000101

    Add the 2 numbers = 00101101 + 11000101 = 11110010

    = 11110010 = -13 in decimal

    4. Subtract (01101010 – 11111101) (i.e. 106 - -2 = 106 + 2 = 108)

    Find 1’s complement of the second number = 00000010

    Add the 2 numbers = 01101010 + 00000010 = 01101100

    = 01101100 = 108 in decimal

    2’s Complement Representation

    The 2’s complement is an alternative complementary representation for signed integers

    See Figure 4.1 for 2’s complement representation of 8-bit number

    2’s complement = 1’s complement + 1

    2’s complement solves the dual zero problem (i.e. –0 and +0) found in 1’s complement

    The –0 is eliminated and the negative scale is shifted to the right by 1 (i.e. add 1)

    2’s complement is more common than 1’s complement in computers

    Advantages

    Addition arithmetic is faster as it does not require an extra end-round carry step

    2’s complement solves the dual zero

    Disadvantages

    Finding complement requires one extra step (i.e. adding 1 after inversion)

    Convert from decimal sign-and-magnitude to 2’s complement

    Similar to 1’s complement with the following differences:

    Complement number = invert bits + 1

    Examples

    Convert –4510 to 8-bit 2’s complement

    The number is negative (the sign is -)

    Convert from decimal to binary = 101101

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Pad with 0’s to get 8-bit representation = 00101101

    Invert the bits = 11010010

    Add 1 = 11010011

    Convert 4510 to 16-bit 2’s complement

    The number is positive

    Convert from decimal to binary = 101101

    Pad with 0’s to get 16-bit representation = 0000000000101101

    = 0000000000101101

    Convert -2510 to 16-bit 1’s complement

    The number is negative (the sign is -)

    Convert from decimal to binary = 11001

    Pad with 0’s to get 16-bit representation = 0000000000011001

    Invert the bits = 1111111111100110

    Add 1 = 1111111111100111

    Convert from 2’s complement to decimal sign-and-magnitude

    Similar to 1’s complement with the following differences:

    Complement number = invert bits + 1

    Examples

    Convert 00101101 to decimal sign-and-magnitude

    The number is positive (most significant bit is 0), no need to complement

    Convert to decimal = 45

    Convert 11010010 to decimal sign-and-magnitude

    The number is negative (most significant bit is 1), then first find the complement

    of the number

    Find 2’s complement = 00101101 + 1 = 00101110

    Convert to decimal = 46

    Since the number is negative, add the negative sign = -46

    Convert 1111111111100110 to decimal sign-and-magnitude

    The number is negative (most significant bit is 1), then first find the complement

    of the number

    Find 2’s complement = 0000000000011001 + 1 = 0000000000011010

    Convert to decimal = 26

    Since the number is negative, add the negative sign = -26

    Addition and Subtraction Arithmetic (2’s complement)

    Addition in 2’s complement is similar to 1’s complement with the following differences:

    The end-carry is dropped rather than added to the result

    Subtraction in 2’s complement is similar to 1’s complement with the exception

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    2’s complement is found for numbers with negative sign instead of 1’s

    complement

    Examples

    1. Add (01101010 + 11111101) (i.e. 106 - 3 = 103)

    01101010 + 11111101 = (1) 01100111

    Drop the end carry

    = 01100111 = 103 in decimal

    2. Add (00101101 + 00111010) (i.e. 45 + 58 = 103)

    00101101 + 00111010

    = 01100111 = 103 in decimal

    3. Subtract (01101010 - 11111101) (i.e. 106 - -3 = 106 + 3 = 109)

    Complement the second number to eliminate the negative sign = 00000010 + 1 =

    00000011

    01101010 + 00000011 = 01101101 = 109 in decimal

    4. Subtract (00101101 - 00111010) (i.e. 45 - 58 = -13)

    Complement the second number to eliminate the negative sign = 11000101 + 1 =

    11000110

    00101101 + 11000110

    = 11110011 = -13 in decimal

    Overflow and Carry Conditions

    Typically, an overflow occur when the result of calculation does not fit into the storage

    space

    In 2’s complement an addition or subtraction overflow occur when the result overflows

    into the sign bit

    An overflow can be detected when the sign of the result is an opposite of the sign of

    both numbers

    In computers, an overflow flag is used to test for an overflow (flag is set/reset at every

    calculation) In 2’s complement an addition or subtraction carry occur when the result

    exceeds the storage space

    A carry flag is used to test for carry (flag is set/reset at every calculation)

    Overflow and carry can occur independent of each other

    4 possible outcomes as a result of addition or subtraction

    No overflow and No carry

    No overflow and carry

    Overflow and no carry

    Overflow and carry

    Overflow produces an incorrect result

    Carry still produces a correct result

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Examples (addition of two 4-bit 2’s complement numbers)

    0100 + 0010 = 0110 (4+2 = 6) no overflow and no carry (result is correct)

    0100 + 0110 = 1010 (4+6 = -6) overflow and no carry (result is incorrect)

    1100 + 1110 = (1) 1010 (-4-2 = -6) no overflow and carry (result is correct)

    1100 + 1010 = (1) 0110 (-4-6 = 6) overflow and carry (result is incorrect)

    Binary Arithmetic:

    Addition

    Adding unsigned numbers

    Adding unsigned numbers in binary is quite easy. Recall that with 4 bit numbers we

    can represent numbers from 0 to 15. Addition is done exactly like adding decimal

    numbers, except that you have only two digits (0 and 1). The only number facts to

    remember are that

    0+0 = 0, with no carry,

    1+0 = 1, with no carry,

    0+1 = 1, with no carry,

    1+1 = 0, and you carry a 1.

    so to add the numbers 0610=01102 and 0710=01112 (answer=1310=11012) we can write

    out the calculation (the results of any carry is shown along the top row, in italics).

    Decimal Unsigned Binary

    1 (carry)

    06

    +07

    13

    110 (carry)

    0110

    +0111

    1101

    The only difficulty adding unsigned numbers occurs when you add numbers that are

    too large. Consider 13+5.

    Decimal Unsigned Binary

    0 (carry)

    13

    +05

    18

    1101 (carry)

    1101

    +0101

    10010

    The result is a 5 bit number. So the carry bit from adding the two most significant bits

    represents a results that overflows (because the sum is too big to be represented with

    the same number of bits as the two addends).

    Adding signed numbers

    Adding signed numbers is not significantly different from adding unsigned numbers.

    Recall that signed 4 bit numbers (2's complement) can represent numbers between -8

    and 7. To see how this addition works, consider three examples.

    Decimal Signed Binary

    -2

    +3

    1

    1110 (carry)

    1110

    +0011

    0001

    Decimal Signed Binary

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    -5

    +3

    -2

    011 (carry)

    1011

    +0011

    1110

    Decimal Signed Binary

    -4

    -3

    -7

    1100 (carry)

    1100

    +1101

    1001

    In this case the extra carry from the most significant bit has no meaning. With signed

    numbers there are two ways to get an overflow -- if the result is greater than 7, or less

    than -8. Let's consider these occurrences now.

    Decimal Signed Binary

    6

    +3

    9

    110 (carry)

    0110

    +0011

    1001

    Decimal Signed Binary

    -7

    -3

    -10

    1001 (carry)

    1001

    +1101

    0110

    Obviously both of these results are incorrect, but in this case overflow is harder to

    detect. But you can see that if two numbers with the same sign (either positive or

    negative) are added and the result has the opposite sign, an overflow has occurred.

    Adding fractions

    There is no further difficult in adding two signed fractions, only the interpretation of

    the results differs. For instance consider addition of two Q3 numbers shown (compare

    to the example with two 4 bit signed numbers, above).

    Decimal Fractional Binary

    -0.25

    +0.375

    0.125

    1110 (carry)

    1110

    +0011

    0001

    Decimal Fractional Binary

    -0.625

    +0.375

    -0.25

    011 (carry)

    1011

    +0011

    1110

    Decimal Fractional Binary

    -0.5

    -0.375

    -0.875

    1100 (carry)

    1100

    +1101

    1001

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    If you look carefully at these examples, you'll see that the binary representation and

    calculations are the same as before, only the decimal representation has changed. This

    is very useful because it means we can use the same circuitry for addition, regardless

    of the interpretation of the results.

    Even the generation of overflows resulting in error conditions remains unchanged

    (again compare with above)

    Decimal Fractional Binary

    0.75

    +0.375

    1.125

    110 (carry)

    0110

    +0011

    1001

    Decimal Fractional Binary

    -0.875

    -0.375

    -1.25

    1001 (carry)

    1001

    +1101

    0110

    Multiplication

    Multiplying unsigned numbers

    Multiplying unsigned numbers in binary is quite easy. Recall that with 4 bit numbers

    we can represent numbers from 0 to 15. Multiplication can be performed done exactly

    as with decimal numbers, except that you have only two digits (0 and 1). The only

    number facts to remember are that 0*1=0, and 1*1=1 (this is the same as a logical

    "and").

    Multiplication is different than addition in that multiplication of an n bit number by an

    m bit number results in an n+m bit number. Let's take a look at an example where

    n=m=4 and the result is 8 bits

    Decimal Binary Decimal Binary

    10

    x6

    60

    1010

    x0110

    0000

    1010

    1010

    +0000

    0111100

    13

    x14

    182

    1101

    x1110

    0000

    1101

    1101

    +1101

    10110110

    In this case the result was 7 bit, which can be extended to 8 bits by adding a 0 at the

    left. When multiplying larger numbers, the result will be 8 bits, with the leftmost set to

    1, as shown.

    As long as there are n+m bits for the result, there is no chance of overflow. For 2 four

    bit multiplicands, the largest possible product is 15*15=225, which can be represented

    in 8 bits.

    Multiplying signed numbers

    There are many methods to multiply 2's complement numbers. The easiest is to simply

    find the magnitude of the two multiplicands, multiply these together, and then use the

    original sign bits to determine the sign of the result. If the multiplicands had the same

    sign, the result must be positive, if they had different signs, the result is negative.

    Multiplication by zero is a special case (the result is always zero, with no sign bit).

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Multiplying fractions

    As you might expect, the multiplication of fractions can be done in the same way as the

    multiplication of signed numbers. The magnitudes of the two multiplicands are

    multiplied, and the sign of the result is determined by the signs of the two

    multiplicands.

    There are a couple of complications involved in using fractions. Although it is almost

    impossible to get an overflow (since the multiplicands and results usually have

    magnitude less than one), it is possible to get an overflow by multiplying -1x-1 since

    the result of this is +1, which cannot be represented by fixed point numbers.

    The other difficulty is that multiplying two Q3 numbers, obviously results in a Q6

    number, but we have 8 bits in our result (since we are multiplying two 4 bit numbers).

    This means that we end up with two bits to the left of the decimal point. These are sign

    extended, so that for positive numbers they are both zero, and for negative numbers

    they are both one. Consider the case of multiplying -1/2 by -1/2 (using the method

    from the textbook):

    Decimal Fractional Binary

    -0.5

    x0.5

    -0.25

    1100

    x0100

    0000

    0000

    +111100

    11110000

    This obviously presents a difficulty if we wanted to store the number in a Q3 result,

    because if we took just the 4 leftmost bits, we would end up with two sign bits. So what

    we'd like to do is shift the number to the left by one and then take the 4 leftmost bit.

    This leaves us with 1110 which is equal to -1/4, as expected.

    Binary Subtraction

    For binary subtraction, there are four facts instead of one hundred:

    0 – 0 = 0

    1 – 0 = 1

    1 – 1 = 0

    10 – 1 = 1

    The first three are the same as in decimal. The fourth fact is the only new one; it is the

    borrow case. It applies when the “top” digit in a column is 0 and the “bottom” digit is 1.

    (Remember: in binary, 10 is pronounced “one-zero” or “two.”)

    Example – Subtraction:

    Now let’s subtract 1011.11 from 10101.101, following the same algorithm used for

    decimal numbers:

    Steps of Binary Subtraction

    Step 1: 1 – 0 = 1.

    Step 2: Borrow to make 10 – 1 = 1.

    Step 3: Borrow to make 10 – 1 = 1.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Step 4: Cascaded borrow to make 10 – 1 = 1.

    Step 5: 1 – 1 = 0.

    Step 6: 0 – 0 = 0.

    Step 7: Borrow to make 10 – 1 = 1.

    Binary Division

    Binary division is similar to decimal division. It is called as the long division procedure.

    Example − Division

    Let’s return to the example of the introduction, 1011.11/11. Here it is broken down

    into steps, following the same algorithm I used for decimal numbers:

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Steps of Binary Division

    Step 0

    Does 11 go into 1? No, because it’s greater than 1. Does 11 go into 10? No, because it’s

    greater than 10. Does 11 go into 101? Yes, because it’s less than or equal to 101.

    (Remember, these are binary numerals; pronounce them “one-one”, “one-zero”, “one-

    zero-one”, etc.)

    Step 1

    1. Divide: Does 11 go into 101? (Yes, we already know that from step 0.) How

    many times does it go in? One time. There is no guessing. It’s easy to see

    11 is less than 101, so we know it goes in. And if it goes in, it goes in only

    once.

    2. Multiply: 1 x 11 = 11. (Remember how simple it is to “multiply” a binary

    number by a single digit — just copy the number down if that single digit

    is 1, or write down 0 if that single digit is 0.)

    3. Subtract: 101 – 11 = 10.

    4. Bring down: Bring down the 1 to make 101.

    Step 2

    1. Divide: Does 11 go into 101? Yes, 1 time.

    2. Multiply: 1 x 11 = 11.

    3. Subtract: 101 – 11 = 10.

    4. Bring down: Bring down the 1 to make 101.

    Step 3

    1. Divide: Does 11 go into 101? Yes, 1 time.

    2. Multiply: 1 x 11 = 11.

    3. Subtract: 101 – 11 = 10.

    4. Bring down: Bring down the 1 to make 101.

    Step 4

    1. Divide: Does 11 go into 101? Yes, 1 time.

    2. Multiply: 1 x 11 = 11.

    3. Subtract: 101 – 11 = 10.

    4. Bring down: Bring down the 0 to make 100.

    Step 5

    1. Divide: Does 11 go into 100? Yes, 1 time.

    2. Multiply: 1 x 11 = 11.

    3. Subtract: 100 – 11 = 1.

    4. Bring down: Bring down the 0 to make 10.

    Step 6

    1. Divide: Does 11 go into 10? No (write down a 0).

    2. Multiply: (We don’t need to record this step; we’re just going to get 0.)

    3. Subtract: (We don’t need to record this step; we’re just going to get 10.)

    4. Bring down: Bring down the 0 to make 100.

    Step 7

    We stop here, recognizing that we divided 100 by 11 two steps ago. This means we have

    a two-digit cycle (10) from here on out. The quotient is 11.1110.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Octal Addition

    Following octal addition table will help you to handle octal addition.

    To use this table, simply follow the directions used in this example: Add 68 and 58.

    Locate 6 in the A column then locate the 5 in the B column. The point in 'sum' area

    where these two columns intersect is the 'sum' of two numbers.

    68 + 58 = 138.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Example − Addition

    Addition, Subtraction, Multiplication, Division of two Octal numbers

    1. Find addition of (321)8 and (47)8

    1

    3 2 1

    + 0 4 7

    3 7 0

    2. Find Subtraction of (321)8 and (47)8

    9

    2 1 9

    3 2 1

    - 0 4 7

    2 5 2

    3. Find multiplication of (321)8 and (47)8

    321

    × 47

    15040

    2667

    17727

    4. Find division of (321)8 and (7)8

    3 5

    7 | 3 2 1

    | 2 5

    |

    |

    5 1

    |

    4 3

    |

    |

    6

    Here, Divisor = 7

    Dividend = 321

    Quotient = 35

    Remainder = 6

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Octal Subtraction

    The subtraction of octal numbers follows the same rules as the subtraction of numbers

    in any other number system. The only variation is in borrowed number. In the decimal

    system, you borrow a group of 1010. In the binary system, you borrow a group of 210. In

    the octal system you borrow a group of 810.

    Example − Subtraction

    Hexadecimal Arithmetic

    The arithmetical operations on base 16 hexadecimal numbers can be performed in the

    similar they are accomplished on decimal numbers.

    Tables for hexadecimal addition and multiplication are used for this purpose.

    The arithmetic operations differ from those done on decimal numbers as

    described below:

    1. The sum 16 is carried over to the next higher place as 1 as 10 is carried over as 1 in

    decimal addition.

    2. When 1 is borrowed from the immediate higher place, it is counted as 16 instead of

    10 in decimal subtraction.

    Let us look into more detail how hexadecimal arithmetical operations are performed.

    Hexadecimal Arithmetic Examples

    Hexadecimal Addition:

    The Addition table below shows the sum for all possible combination of digits in

    addition

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Example: Add 16F16 + 4A216.

    1 1 ← Carried over digits

    1 6 F

    + 4 A 2

    ----------------

    6 1 1

    -----------------

    The digits in unit's place F are 2. From the table, F + 2 = 1116 from which 1 is written in

    unit's place and 1 is carried over to the next higher (16) place.

    The digits in 16's place are added as

    1 + 6 + A = 7 + A = 1116 (From table) out of which, 1 is written down as sum and 1 is

    carried to the next higher (162) place.

    The digits in 162 's place add as 1 + 1 + 4 = 616.

    Thus 16F16 + 4A216 = 61116.

    Hexadecimal Subtraction:

    The rule to be remembered for subtraction is the digit borrowed from the immediate

    higher place is counted as 16.

    Example: Subtract B4A16 from C3916.

    16 16 ← Borrowed

    B 2 ← Remaining digit after borrowing

    C 3 9

    - B 4 A

    ------------------

    E F

    -------------------

    In units place, A the bigger number is to be subtracted from 9. So, 1 digit from 16's

    place is borrowed and 16 + 9 = 25.

    A is subtracted from 25.

    25 - A16 = F16 (Note the values of A and F are 10 and 15).

    As 1 is borrowed from 3, now for the next place 4 is to be subtracted from 2. This

    again requires borrowing from the next higher place.

    16 + 2 - 4 = 18 - 4 = E16.

    Now, for the next place, B is to B subtracted from B remaining after lending 1.B -B = 0.

    Thus C3916 - B4A16 - = EF16.

    Hexadecimal Multiplication:

    The following table gives products of all combinations of two single digits.

    While multiplying, if the product consists of two digits, the digit on the left is carried

    over and added to the product in the next place.

    Example:

    Find the product of 1A816 and AF16.

    6 5 ← Digits carried over in second multiplication 9 7 ← Digits carried over in first multiplication. 1 A 8 x A F --------------- 1 8 D 8 1 0 9 0 0 -------------------------- 1 2 1 D 8 ---------------------------

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    First the digit F in the number AF16 is multiplied with each of the digits in the number 1A816. F x 8 = 78. The digit 8 is written below in the product row and 7 is carried over to the next place to be added with the next product. F x A = 9616 and 9616 + 716 = 9D16. D is written in the product row and 9 is carried over to the next place F x 1 = F. and F16 + 916 = 1816 . The second row of multiplication is done in a similar manner, by multiplying the digit A with each of the digits in 1A816. The two products are then added to get the final product. Thus 1A816 x AF16 = 121D816.

    BCD or Binary Coded Decimal:

    BCD or Binary Coded Decimal is that number system or code which has the binary

    numbers or digits to represent a decimal number. A decimal number contains 10 digits

    (0-9). Now the equivalent binary numbers can be found out of these 10 decimal

    numbers. In case of BCD the binary number formed by four binary digits, will be the

    equivalent code for the given decimal digits. In BCD we can use the binary number

    from 0000-1001 only, which are the decimal equivalent from 0-9 respectively. Suppose

    if a number have single decimal digit then its equivalent Binary Coded Decimal will be

    the respective four binary digits of that decimal number and if the number contains

    two decimal digits then its equivalent BCD will be the respective eight binary of the

    given decimal number. Four for the first decimal digit and next four for the second

    decimal digit. It may be cleared from an example.

    Let, (12)10 be the decimal number whose equivalent Binary coded decimal will be

    00010010. Four bits from L.S.B is binary equivalent of 2 and next four is the binary

    equivalent of 1.

    Table given below shows the binary and BCD codes for the decimal numbers 0 to 15.

    From the table below, we can conclude that after 9 the decimal equivalent binary

    number is of four bit but in case of BCD it is an eight bit number. This is the main

    difference between Binary number and binary coded decimal. For 0 to 9 decimal

    numbers both binary and BCD is equal but when decimal number is more than one bit

    BCD differs from binary.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Decimal number

    Binary number

    Binary Coded Decimal(BCD)

    0 0000 0000

    1 0001 0001

    2 0010 0010

    3 0011 0011

    4 0100 0100

    5 0101 0101

    6 0110 0110

    7 0111 0111

    8 1000 1000

    9 1001 1001

    10 1010 0001 0000

    11 1011 0001 0001

    12 1100 0001 0010

    13 1101 0001 0011

    14 1110 0001 0100

    15 1111 0001 0101

    Binary floating point number:

    Here it is not a decimal point we are moving but a binary point and because it moves it

    is referred to as floating. What we will look at below is what is referred to as the IEEE

    754 Standard for representing floating point numbers. The standard specifies the

    number of bits used for each section (exponent, mantissa and sign) and the order in

    which they are represented.

    The standard specifies the following formats for floating point numbers:

    Single precision, which uses 32 bits and has the following layout:

    1 bit for the sign of the number. 0 means positive and 1 means negative.

    8 bits for the exponent.

    23 bits for the mantissa.

    Double precision, which uses 64 bits and has the following layout.

    1 bit for the sign of the number. 0 means positive and 1 means negative.

    11 bits for the exponent.

    52 bits for the mantissa.

    eg. 0 00011100010 0100001000000000000001110100000110000000000000000000

    Double precision has more bits, allowing for much larger and much smaller numbers

    to be represented. As the mantissa is also larger, the degree of accuracy is also

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    increased (remember that many fractions cannot be accurately represented in binary).

    Whilst double precision floating point numbers have these advantages, they also

    require more processing power. With increases in CPU processing power and the move

    to 64 bit computing a lot of programming languages and software just default to double

    precision.

    We will look at how single precision floating point numbers work below (just because

    it's easier). Double precision works exactly the same, just with more bits.

    The sign bit

    This is the first bit (left most bit) in the floating point number and it is pretty easy. As

    mentioned above if your number is positive, make this bit a 0. If your number is

    negative then make it a 1.

    The Exponent

    The exponent gets a little interesting. Remember that the exponent can be positive (to

    represent large numbers) or negative (to represent small numbers, ie fractions). Your

    first impression might be that two's complement would be ideal here but the standard

    has a slightly different approach. This is done as it allows for easier processing and

    manipulation of floating point numbers.

    With 8 bits and unsigned binary we may represent the numbers 0 through to 255. To

    allow for negative numbers in floating point we take our exponent and add 127 to it.

    The range of exponents we may represent becomes 128 to -127. 128 is not allowed

    however and is kept as a special case to represent certain special numbers as listed

    further below.

    Eg. let's say:

    We want our exponent to be 5. 5 + 127 is 132 so our exponent becomes -

    10000100

    We want our exponent to be -7. -7 + 127 is 120 so our exponent becomes –

    01111000

    The Mantissa

    In scientific notation remember that we move the point so that there is only a single

    (non zero) digit to the left of it. When we do this with binary that digit must be 1 as

    there is no other alternative. The creators of the floating point standard used this to

    their advantage to get a little more data represented in a number.

    After converting a binary number to scientific notation, before storing in the mantissa

    we drop the leading 1. This allows us to store 1 more bit of data in the mantissa.

    eg.

    If our number to store was 111.00101101 then in scientific notation it would be

    1.1100101101 with an exponent of 2 (we moved the binary point 2 places to the left).

    We drop the leading 1. and only need to store 1100101101.

    If our number to store was 0.0001011011 then in scientific notation it would be

    1.011011 with an exponent of -4 (we moved the binary point 4 places to the right). We

    drop the leading 1. and only need to store 011011.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Binary Codes : In the coding, when numbers, letters or words are represented by a specific group of

    symbols, it is said that the number, letter or word is being encoded. The group of

    symbols is called as a code. The digital data is represented, stored and transmitted as

    group of binary bits. This group is also called as binary code. The binary code is

    represented by the number as well as alphanumeric letter.

    Advantages of Binary Code

    Following is the list of advantages that binary code offers.

    Binary codes are suitable for the computer applications.

    Binary codes are suitable for the digital communications.

    Binary codes make the analysis and designing of digital circuits if we use the

    binary codes.

    Since only 0 & 1 are being used, implementation becomes easy.

    Classification of binary codes

    The codes are broadly categorized into following four categories.

    Weighted Codes

    Non-Weighted Codes

    Binary Coded Decimal Code

    Alphanumeric Codes

    Error Detecting Codes

    Error Correcting Codes

    Weighted Codes

    Weighted binary codes are those binary codes which obey the positional weight

    principle. Each position of the number represents a specific weight. Several systems of

    the codes are used to express the decimal digits 0 through 9. In these codes each

    decimal digit is represented by a group of four bits.

    Non-Weighted Codes

    In this type of binary codes, the positional weights are not assigned. The examples of

    non-weighted codes are Excess-3 code and Gray code.

    Excess-3 code

    The Excess-3 code is also called as XS-3 code. It is non-weighted code used to express

    decimal numbers. The Excess-3 code words are derived from the 8421 BCD code words

    adding (0011)2 or (3)10 to each code word in 8421. The excess-3 codes are obtained as

    follows −

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Example

    Gray Code

    It is the non-weighted code and it is not arithmetic codes. That means there are no

    specific weights assigned to the bit position. It has a very special feature that, only one

    bit will change each time the decimal number is incremented as shown in fig. As only

    one bit changes at a time, the gray code is called as a unit distance code. The gray code

    is a cyclic code. Gray code cannot be used for arithmetic operation.

    Application of Gray code

    Gray code is popularly used in the shaft position encoders.

    A shaft position encoder produces a code word which represents the angular

    position of the shaft.

    Binary Coded Decimal (BCD) code

    In this code each decimal digit is represented by a 4-bit binary number. BCD is a way

    to express each of the decimal digits with a binary code. In the BCD, with four bits we

    can represent sixteen numbers (0000 to 1111). But in BCD code only first ten of these

    are used (0000 to 1001). The remaining six code combinations i.e. 1010 to 1111 are

    invalid in BCD.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Advantages of BCD Codes

    It is very similar to decimal system.

    We need to remember binary equivalent of decimal numbers 0 to 9 only.

    Disadvantages of BCD Codes

    The addition and subtraction of BCD have different rules.

    The BCD arithmetic is little more complicated.

    BCD needs more number of bits than binary to represent the decimal number.

    So BCD is less efficient than binary.

    Alphanumeric codes

    A binary digit or bit can represent only two symbols as it has only two states '0' or '1'.

    But this is not enough for communication between two computers because there we

    need many more symbols for communication. These symbols are required to represent

    26 alphabets with capital and small letters, numbers from 0 to 9, punctuation marks

    and other symbols.

    The alphanumeric codes are the codes that represent numbers and alphabetic

    characters. Mostly such codes also represent other characters such as symbol and

    various instructions necessary for conveying information. An alphanumeric code

    should at least represent 10 digits and 26 letters of alphabet i.e. total 36 items. The

    following three alphanumeric codes are very commonly used for the data

    representation.

    American Standard Code for Information Interchange (ASCII).

    Extended Binary Coded Decimal Interchange Code (EBCDIC).

    Five bit Baudot Code.

    ASCII code is a 7-bit code whereas EBCDIC is an 8-bit code. ASCII code is more

    commonly used worldwide while EBCDIC is used primarily in large IBM computers.

    Decimal Binary 8421 2421 5211 Excess-3 Gray Code

    0 0 0000 0000 0000 0011 0000

    1 1 0001 0001 0001 0100 0001

    2 10 0010 0010 0011 0101 0011

    3 11 0011 0011 0101 0110 0010

    4 100 0100 0100 0111 0111 0110

    5 101 0101 1011 1000 1000 0111

    6 110 0110 1100 1010 1001 0101

    7 111 0111 1101 1100 1010 0100

    8 1000 1000 1110 1110 1011 1100

    9 1001 1001 1111 1111 1100 1101

    10 1010 1111

    11 1011 1110

    12 1100 1010

    13 1101 1011

    14 1110 1001

    15 1111 1000

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Error Codes : There are binary code techniques available to detect and correct data during data

    transmission.

    What is Error?

    Error is a condition when the output information does not match with the input

    information. During transmission, digital signals suffer from noise that can introduce

    errors in the binary bits travelling from one system to other. That means a 0 bit may

    change to 1 or a 1 bit may change to 0.

    Error-Detecting codes

    Whenever a message is transmitted, it may get scrambled by noise or data may get

    corrupted. To avoid this, we use error-detecting codes which are additional data added

    to a given digital message to help us detect if an error occurred during transmission of

    the message. A simple example of error-detecting code is parity check.

    Error-Correcting codes

    Along with error-detecting code, we can also pass some data to figure out the original

    message from the corrupt message that we received. This type of code is called an

    error-correcting code. Error-correcting codes also deploy the same strategy as error-

    detecting codes but additionally, such codes also detect the exact location of the

    corrupt bit.

    In error-correcting codes, parity check has a simple way to detect errors along with a

    sophisticated mechanism to determine the corrupt bit location. Once the corrupt bit is

    located, its value is reverted (from 0 to 1 or 1 to 0) to get the original message.

    How to Detect and Correct Errors?

    To detect and correct the errors, additional bits are added to the data bits at the time of

    transmission.

    The additional bits are called parity bits. They allow detection or correction of

    the errors.

    The data bits along with the parity bits form a code word.

    Parity Checking of Error Detection

    It is the simplest technique for detecting and correcting errors. The MSB of an 8-bits

    word is used as the parity bit and the remaining 7 bits are used as data or message

    bits. The parity of 8-bits transmitted word can be either even parity or odd parity.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    Even parity -- Even parity means the number of 1's in the given word including the

    parity bit should be even (2,4,6,....).

    Odd parity -- Odd parity means the number of 1's in the given word including the

    parity bit should be odd (1,3,5,....).

    Use of Parity Bit

    The parity bit can be set to 0 and 1 depending on the type of the parity required.

    For even parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire

    word is even. Shown in fig. (a).

    For odd parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire

    word is odd. Shown in fig. (b).

    How Does Error Detection Take Place?

    Parity checking at the receiver can detect the presence of an error if the parity of the

    receiver signal is different from the expected parity. That means, if it is known that the

    parity of the transmitted signal is always going to be "even" and if the received signal

    has an odd parity, then the receiver can conclude that the received signal is not

    correct. If an error is detected, then the receiver will ignore the received byte and

    request for retransmission of the same byte to the transmitter.

  • Vignana Bharathi Institute of Technology UNIT 1 DLD

    potharajuvidyasagar.wordpress.com P VIDYA SAGAR

    BOOLEAN ALGEBRA & LOGIC GATES :

    Logic gates are electronic circuits that can be used to implement the most elementary

    logic expressions, also known as Boolean expressions. The logic gate is the most basic

    building block of combinational logic. There are three basic logic gates, namely the OR

    gate, the AND gate and the NOT gate. Other logic gates that are derived from these

    basic gates are the NAND gate, the NOR gate, the EXCLUSIVEOR gate and the

    EXCLUSIVE-NOR gate. This chapter deals with logic gates and implementations using

    NAND and NOR gates followed by simplification of Boolean functions using Boolean

    Laws and theorems and using K-maps.

    Positive and Negative Logic

    The binary variables can have either of the two states, i.e. the logic ‘0’ state or the logic

    ‘1’ state. These logic states in digital systems such as computers, for instance, are

    represented by two different voltage levels or two different current levels. If the more

    positive of the two voltage or current levels represents a logic ‘1’ and the less positive of

    the two levels represents a logic ‘0’, then the logic system is referred to as a positive

    logic system. If the more positive of the two voltage or current levels represents a logic

    ‘0’ and the less positive of the two levels represents a logic ‘1’, then the logic system is

    referred to as a negative logic system.

    If the two voltage levels are 0 V and +5 V, then in the positive logic system the 0 V

    represents logic ‘0’ and the +5 V represents logic ‘1’. In the negative logic system, 0 V

    represents logic ‘1’ and 5 V represents logic ‘0’. If the two voltage levels are 0 V and −5

    V, then in the positive logic system the 0 V represents a logic ‘1’ and the −5 V

    represents a logic ‘0’. In the negative logic system, 0 V represents logic ‘0’ and −5 V

    represents logic ‘1’.

    Logic Gates

    The logic gate is the most basic building block of any digital system, including

    computers. Each one of the basic logic gates is a piece of hardware or an electronic

    circuit that can be used to implement some basic logic expression. While laws of

    Boolean algebra could be used to do manipulation with binary variables and simplify

    logic expressions, these are actually implemented in a digital system with the help of

    electronic circuits called logic gates. The three basic logic gates are the OR gate, the

    AND gate and the NOT gate.

    OR Gate

    A logic gate used to perform the operation of logical addition is called an OR gate. An

    OR gate performs an ORing operation on two or more than two logic variables. The OR

    operation on two independent logic variables A and B is written as Y = A+B and reads

    as Y equals A OR B. An OR gate is a logic circuit with two or more inputs and one

    output. The output of an OR gate is LOW only when all o