Basic Digital Electronics - Unit 2

Embed Size (px)

Citation preview

  • 8/12/2019 Basic Digital Electronics - Unit 2

    1/36

    2 NUMBER SYSTEMS AND CODESAt the end of the lesson, students should be able to:

    1. Count in the binary number system.2. Convert from the decimal form to binary form and from binary form to

    decimal form including fractions.

    3. Add and subtract binary numbers including fractions.4. Determine ls and 2s compliments of a binary number.5. Express signed numbers in binary form.6. Carry out arithmetic operations with signed binary numbers.7. Convert between the binary and octal number systems.8. Convert between the binary and hexadecimal number system.9. Express decimal numbers in binary coded decimal (BCD).10. Add BCD numbers.1. Understand the Gray and ASCII code is used.

  • 8/12/2019 Basic Digital Electronics - Unit 2

    2/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201014

    2.1 COUNT IN BINARY NUMBER SYSTEM

    Only have 2 digits 0 and 1 (known as bits)

    It is expressed as a base of 2.

    24 23

    CONVERT FROM DECIMAL TO BINARY FORM

    It use repeated division-by-2

    Example:

    Convert 1210to binary form.

    Solution:

    1210

    = 11002

    Check:

    Weight 23 22 21 20 = 23+ 22= 8 + 4 = 12Binary Number 1 1 0 0

    Weight 22 21 20 2-1 2-2 2-3 2-4

    Binary

    Number1 0 1 0 0 1 0 1 0

    MSB LSB

    2.2 BINARY AND DECIMAL FORM TO BINARY FORM

    Remain2 12 0

    2 6 0

    2 3 1

    2 1 1

    From below

    2 012

    10

    = 1 1 0 02

  • 8/12/2019 Basic Digital Electronics - Unit 2

    3/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    CONVERT DECIMAL TO BINARY FORM INCLUDING FRACTION

    Fractional binary numbers are expressed as negative powers of 2.

    Multiply the decimal numbers by 2 repeatedly until the fraction become 0 or

    at the place you want.

    Example 1:

    Convert 0.312510to binary form.

    Solution:

    Carry = 0 . 0 1 0 1

    0.3125 2 = 0.625 0

    0.625 2 = 1.25 10.25 2 = 0.50 0

    0.5 2 = 1.00 1

    Fatma Syazana Zaini,

    IKM Besut, 201015

    Stop until the fraction

    become 0.

    Example 2:Convert 0.634210to binary form.

    Solution:

    Carry = . 1 0 1 00.6342 2 = 1.2684 10.2684 2 = 0.5368 00.5368 2 = 1.0736 10.0736 2 = 0.1472 0

    Stop at the place you

    want

  • 8/12/2019 Basic Digital Electronics - Unit 2

    4/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201016

    CONVERT FROM BINARY FORM TO DECIMAL POINT

    Multiply each bit by positional weight and add the weight of all bits that are

    1

    Discard the weight of all bits that are 0

    Example:

    Express 11011012to decimal form.

    Solution:

    Weight 26 25 24 23 22 21 20Binary Number 1 1 0 1 1 0 111011012= 26+ 25+ 23+ 22+ 21= 64 + 32 + 8 + 4 + 1 = 109

    CONVERT FROM BINARY FORM TO DECIMAL FORM INCLUDING FRACTION

    Example:

    1. Convert 0.1011 to decimal point.

    Solution:

    Weight 20 2-1 2-2 2-3 2-4Binary Number 0. 1 0 1 1

    0.10112 = 0 20) + 1 2 -1) + 0 2 -2) + 1 2 -3) + 1 2 -4)= 0 0) + 1 1/2) + 0 1/4) + 1 1/8) + 1 1/16)= 0.5 + 0.125 + 0.0625= 0.6875

  • 8/12/2019 Basic Digital Electronics - Unit 2

    5/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    2. Convert 0.11001 to decimal point.

    Solution:

    Weight 20 2-1 2-2 2-3 2-4 2-5Binary Number 0. 1 1 0 0 1

    0.110012 = 2 -1+ 2-2+ 2-5= 0.5 + 0.25 + 0.03125= 0.78125

    Fatma Syazana Zaini,

    IKM Besut, 201017

    2.3 ADD AND SUBTRACT BINARY NUMBER INCLUDING

    ADD BINARY NUMBER

    Basic rules:

    Carry

    0 + 0 = 0 0 0 + 1 = 1 0 1 + 0 = 1 0 1 + 1 = 0 1 1 + 1 + carry) =1 1

    Example:

    1. Add 1012to 102.

    Check:

    1 0 1 5+ 1 0 + 2

    1 1 1 7

  • 8/12/2019 Basic Digital Electronics - Unit 2

    6/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    2. Add 10102to 112.

    1 Check:

    1 0 1 0 10+ 1 1 + 3

    1 1 0 1 13

    3. Add 11012to 1102.

    1 Check:

    1 1 0 1 13+ 1 1 0 + 61 0 0 1 1 19

    SUBTRACT BINARY NUMBER

    Case 1:

    Check:

    1 1 0 1 13- 1 0 0 - 4

    1 0 0 1 9

    Case 2:

    Check:When borrowing 1 from

    left, it becomes 10.

    10 1 = 1

    (2 - 1 = 1)

    1 10 0 1 9- 1 0 0 - 4

    1 0 1 5

    Fatma Syazana Zaini,

    IKM Besut, 201018

  • 8/12/2019 Basic Digital Electronics - Unit 2

    7/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Case 3:

    Fatma Syazana Zaini,

    IKM Besut, 201019

    0 1 1 1 Check:

    1 0 0 0 10 1 33- 0 1 0 1 0 - 10

    1 0 1 1 1 23

    1 is borrowed from this column leaving 0

    1s and 2s compliment of binary numbers are important because they permit the

    representation of negative (-ve) numbers.

    1S COMPLEMENTS

    The 1s compliment of a binary is found by changing all 1s to 0s and all 0sto 1s.

    In other words, change each bits in the number to its complement. Example:

    Find the 1s complement of 11012.

    Solution:

    1 1 0 1

    0 0 1 0

    11012= 00102

    2.4 1S AND 2S COMPLEMENTS OF BINARY NUMBER

    When 1 is borrowed from left, it

    becomes 1

    When 1 is borrowed from left, itbecomes 102. 102 12= 12

    1 0 = 0 without borrow

  • 8/12/2019 Basic Digital Electronics - Unit 2

    8/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    2S COMPLEMENTS

    The 2s complement of a binary number is formed by taking the 1s

    complement of the number and adding 1 to the least significant bit (LSB)

    position.

    Example 1:

    Find the 2s complement of 11012.

    Solution:

    1 1 0 1 Binary number

    0 0 1 0 1s complement+ 1

    0 0 1 1 2s complement

    Example 2:

    Find the 2s complement of 10011012.

    Solution:

    1 0 0 1 1 0 1 Binary number

    0 1 1 0 0 1 0 1s complement+ 1 Add 1

    0 1 1 0 0 1 1 2s complement

    Fatma Syazana Zaini,

    IKM Besut, 201020

  • 8/12/2019 Basic Digital Electronics - Unit 2

    9/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201021

    THE SIGNED BITS

    The left most bitin a signed binary number is the sign bit, which tells you

    whether the number is positive or negative.

    A 0 sign bit indicates a positive number, and a 1 sign bit indicates a

    negative number.

    SIGN MAGNITUDE FORM

    When a signed binary number is represented in sign magnitude, the left

    most bits is the sign bit andthe remaining bits are the magnitude bits.

    The magnitude bits are in true (un-complemented) binary for both positive

    and negative numbers.

    For example, the decimal number +25 is expressed as an 8 bit signed

    number using the sign magnitude form as:

    0 0 0 1 1 0 0 12

    The decimal number 25 is expressed as 1 0 0 1 1 0 0 12

    Sign bit Magnitude bit

    REMEMBER:

    The MSB is the sign bit, which tells us

    weather the number is positive or negative.

    Sign bit 0 = positive

    Sign bit 1 = negative

    2.5 EXPRESS SIGNED NUMBERS IN BINARY FORM

  • 8/12/2019 Basic Digital Electronics - Unit 2

    10/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201022

    1S COMPLEMENT

    Example:

    Using 8 bits, express decimal number +25 in 1s compliment.

    +25 : 0001 1001 binary number

    1110 0110 1s complement

    In 1s complement form, a negative number is the 1s complement of

    the corresponding positive number.(dalam bentuk 1s C, nombor negative adalah 1s C untuk nombor positif)

    2S COMPLEMENT

    Negative number is the 2s complement of the corresponding positive

    number.

    Example:

    Express decimal number -25 as 2s complement.

    0 0 0 1 1 0 0 1 Binary number of +25

    1 1 1 0 0 1 1 0 1s complement

    + 1 Add 1

    1 1 1 0 0 1 1 1 2s complement

    In the 2s complement form, a negative number is the 2s complement of the

    corresponding positive number.

  • 8/12/2019 Basic Digital Electronics - Unit 2

    11/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Example:

    Express the decimal number -39 as an 8 bit number in the sign-magnitude,

    1s complement and 2s complement forms.

    + 39 = 0010 01112In the sign-magnitude form -39 = 1010 01112In 1s complement form -39 :-

    0 0 1 0 0 1 1 1 Binary number (+39)

    1 1 0 1 1 0 0 0 1s complement

    In 2s complementform -39 :-

    0 0 1 0 0 1 1 1 Binary number (+39)

    1 1 0 1 1 0 0 0 1s complement

    Fatma Syazana Zaini,

    IKM Besut, 201023

    + 1 Add 1

    1 1 0 1 1 0 0 1 2s complement (-39)

    ARITHMETIC OPERATIONS WITH SIGNED NUMBERS2.6

    ADDITION IN 2S COMPLEMENT SYSTEM

    o Case 1 : Two positive numbers

    The addition of +7 and +4

    0 0 0 0 0 1 1 1 (+ 7)+ 0 0 0 0 0 1 0 0 (+ 4)

    0 0 0 0 1 0 1 1 + 11) If the sum is positive, therefore, intrue binary

  • 8/12/2019 Basic Digital Electronics - Unit 2

    12/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    o Case 2 : Negative number < Positive number

    The addition of +15 and -6

    0 0 0 0 0 1 1 0 Binary number (+6)

    1 1 1 1 1 0 0 1 1s complement

    Fatma Syazana Zaini,

    IKM Besut, 201024

    + 1 Add 1

    1 1 1 1 1 0 1 0 2s complement (-6)

    1 1 1 1 1 1

    0 0 0 0 1 1 1 1 (+ 15)

    + 1 1 1 1 1 0 1 0 (- 6)

    1 0 0 0 0 1 0 0 1 + 9)If there is a final carry bit, then discard.

    The sum is positive.

    o Case 3 : Positive number < Negative number

    The addition of +16 and -24

    0 0 0 1 1 0 0 0 Binary number (+24)

    1 1 1 0 0 1 1 1 1s complement

    To get -6, change +6 to 2s

    Complement

    + 1 Add 1

    1 1 1 0 1 0 0 0 2s complement (-24)

    0 0 0 1 0 0 0 0 (+ 16)+ 1 1 1 0 1 0 0 0 (- 24)

    1 1 1 1 1 0 0 0 - 8)

  • 8/12/2019 Basic Digital Electronics - Unit 2

    13/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    o Case 4 : Two negative number

    The addition of -5 and -9

    - 5 :- -9 :-

    0 0 0 0 0 1 0 1 (+5) 0 0 0 0 1 0 0 1 (+9)

    1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 0

    Fatma Syazana Zaini,

    IKM Besut, 201025

    + 1 + 1

    1 1 1 1 1 0 1 1 (-5) 1 1 1 1 0 1 1 1 (-9)

    1 1 1 1 1 1 1

    1 1 1 1 1 0 1 1 (- 5)

    + 1 1 1 1 0 1 1 1 (- 9)

    1 1 1 1 1 0 0 1 0 ( - 14)

    The final carry bit is discarded.

    Thesum is negative.

    o Case 5 :- Equal and opposite numberThe addition of -9 and +9

    1 1 1 1 1 1 1

    1 1 1 0 1 1 1 1 - 9 (in 2s complement form)

    + 0 0 0 1 0 0 0 1 + 9

    1 0 0 0 0 0 0 0 0 0

    The final carry bit is discarded.

  • 8/12/2019 Basic Digital Electronics - Unit 2

    14/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201026

    SUBTRACTION IN 2S COMPLEMENT SYSTEM

    Procedure:

    i. Negate the subtrahend will change the subtrahend to its equivalent

    value of opposite sign.

    ii. Add the negation to the minuend the result will represent the

    difference between the subtrahend and minuend.

    iii. Discarded any final carry bit.

    Example:

    Perform each of the following subtractions of the signed numbers:

    a) +8 (+3) = 5

    b) 12 (-9) = 21

    c) -25 (+19) = -44

    d) -120 (-30) = -90

    Solutions:

    a) +8 (+3) = 5 b) 12 (-9) = 21

    1 1 1 1 1

    0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0

    + 1 1 1 1 1 1 0 1 + 0 0 0 0 1 0 0 1

    1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 1

    c) -25 (+19) = -44 d) -120 (-30) = -90

    1 1 1 1 1 1 1 1

    1 1 1 0 0 1 1 1 1 0 0 0 1 0 0 0

    + 1 1 1 0 1 1 0 1 + 0 0 0 1 1 1 1 0

    1 1 1 0 1 0 1 0 0 1 0 1 0 0 1 1 0

  • 8/12/2019 Basic Digital Electronics - Unit 2

    15/36

  • 8/12/2019 Basic Digital Electronics - Unit 2

    16/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    c)

    1 4 0

    0 0 1 1 0 0 0 0 0

    1408= 001 100 0002d)

    7 2 5 6

    1 1 1 0 1 0 1 0 1 1 1 0

    Fatma Syazana Zaini,

    IKM Besut, 201028

    72568= 111 010 101 1102

    BINARY TO OCTAL CONVERSION

    Example:

    Convert each of the following binary numbers to octal.

    a) 110 101 b) 101 111 001

    c) 100 110 011 101 d) 011 010 000 100

    Solution:

    a) 110 101

    6 58

    b) 101 111 001

    5 7 18

    c) 100 110 011 101

    4 6 3 58

    d) 011 010 000 100

    3 2 0 48

  • 8/12/2019 Basic Digital Electronics - Unit 2

    17/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201029

    HEXADECIMAL NUMBERING SYSTEM2.8

    The hexadecimal number system has sixteen (16) digits. It is composed of 16

    digits and alphabets characters.

    Each hexadecimal digit represents a 4-bit binary number as listed in table 2.

    Hexadecimal is widely used in computer and microprocessor application.

    DECIMAL BINARY HEXADECIMAL

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    1213

    14

    15

    0000

    0001

    0010

    0011

    0100

    0101

    0110

    0111

    1000

    1001

    1010

    1011

    11001101

    1110

    1111

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    A

    B

    CD

    E

    F

    Table 2

  • 8/12/2019 Basic Digital Electronics - Unit 2

    18/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    BINARY TO HEXADECIMAL CONVERSION

    Example 1:

    Convert the following binary numbers to hexadecimal.

    Solutions;

    a) 1100 1010 0101 0111

    C A 5 7

    Fatma Syazana Zaini,

    IKM Besut, 201030

    1100 1010 0101 01112= CA57 16

    b) 11 1111 0001 0110 1001

    3 F 1 6 91111110001011010012= 3F16916

    HEXADECIMAL TO BINARY CONVERSION

    Example 1:

    Determine the binary numbers for the following hexadecimal numbers.

    a) 10A416

    1 0 A 4

    0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 010A416= 0001 0000 1010 01002

  • 8/12/2019 Basic Digital Electronics - Unit 2

    19/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    b) CF8E16

    C F 8 E

    1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 0CF8E16=1100 1111 1000 11102

    c) 974216

    9 7 4 2

    1 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0974216= 1001 0111 0100 00102

    Fatma Syazana Zaini,

    IKM Besut, 201031

    DECIMAL TO HEXADECIMAL CONVERSION

    To convert decimal numbers to hexadecimal, the decimal numbers aredivided by 16 using the same repeated-division-method.

    Example 1 :Convert 4428910to hexadecimal numbers.

    Solution:

    Remain 4428910 = A D 0 116 44289 116 2768 016 173 13 = D16 10 10 = A

    04428910= AD0116

  • 8/12/2019 Basic Digital Electronics - Unit 2

    20/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    For fractional decimal number, repeated-multiplication-method is used.

    Example 1:

    Convert 0.678510to hexadecimal numbers.

    Carry = . A D B 20.6785 16 = 0.856 100.856 16 = 0.696 130.696 16 = 0.136 110.136 16 = 0.176 2

    Fatma Syazana Zaini,

    IKM Besut, 201032

    0.678510 = 0.ADB2

    HEXADECIMAL TO DECIMAL CONVERSION

    Example :

    Convert A5C1.0116to decimal numbers.

    Solutions:

    Weight 163 162 161 160 16-1 16-2Hex Number A 5 C 1 . 0 1

    A5C1.0116= 10 163+ 5 162+ 12 161+ 1 160+ 1 16-2= 42433.0039

    REMEMBER:

    For hexadecimal system, if remainder

    larger than 9, replace as follow:

    10 = A 13 = D

    11 = B 14 = E

    12= C 15 = F

  • 8/12/2019 Basic Digital Electronics - Unit 2

    21/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    OCTAL TO HEXADECIMAL CONVERSION

    To convert from octal to hexadecimal number, you can use oct-dec-oct method oroct-bin-hex method.

    Example:

    Convert 74218 to hexadecimal number.

    Solution:

    Octal Number

    Step 1: Expand eachoctal digits to threebinary bit

    Step 2: Result inbinary

    Step 3:Group in four

    Step 4:Convert

    7 4 2 1

    1 1 1 1 0 0 0 1 0 0 0 1

    1 1 1 1 0 0 0 1 0 0 0 1

    1 1 1 1 0 0 0 1 0 0 0 1

    F 1 1

    74218= F11 16

    Fatma Syazana Zaini,

    IKM Besut, 201033

  • 8/12/2019 Basic Digital Electronics - Unit 2

    22/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    HEXADECIMAL TO OCTAL CONVERSION

    Same with octal to hexadecimal conversion, you can either use hex-dec-oct methodor hex-bin-oct method.

    Example:

    Convert E64B16to octal number.

    Solution:

    Hex Number

    Step 1:Expandeach octaldigits to fourbinary bit

    Step 2: Resultin binary

    Step 3: Groupin three

    Step 4:Convert

    E 6 4 B

    1 1 1 0 0 1 1 0 0 1 0 0 1 0 1 1

    1 1 1 0 0 1 1 0 0 1 0 0 1 0 1 1

    1 1 1 0 0 1 1 0 0 1 0 0 1 0 1 1

    1 6 3 1 1 3

    E64B16= 1631138

    Fatma Syazana Zaini,

    IKM Besut, 201034

  • 8/12/2019 Basic Digital Electronics - Unit 2

    23/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201035

    BCD is a way to express each of the decimal digits with a binary code.

    BCD means that each decimal digit 0 through 9 is represented by a binary code

    of four bits.

    There are only ten code groups in the DCB system.

    To express any decimal number in BCD, replace each decimal digit with the

    appropriate 4-bit code.

    DECIMAL

    DIGIT

    BCD

    0 0000

    1 0001

    2 0010

    3 00114 0100

    5 0101

    6 0110

    7 0111

    8 1000

    9 1001

    Table 3

    Example :

    Convert each of the following numbers to BCD.

    a) 35 b) 98 c) 170 d) 2469

    Solutions:

    a)

    3 5

    0 0 1 1 0 1 0 135 =0011 0101BCD

    DECIMAL NUMBERS IN BINARY CODED DECIMAL (BCD)

    FORM2.9

  • 8/12/2019 Basic Digital Electronics - Unit 2

    24/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    b)

    9 8

    1 0 0 1 1 0 0 098 = 1001 1000BCD

    c)

    1 7 0

    0 0 0 1 0 1 1 1 0 0 0 0170 = 0001 0111 0000BCD

    d)

    2 4 6 9

    0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 12469 = 0010 0100 1001 1001BCD

    Fatma Syazana Zaini,

    IKM Besut, 201036

    Example :

    Convert each of the following BCD to decimal.

    a) 1000 0110 b) 0011 0101 0001

    Solutions:

    a) 1000 0110

    8 6

    1000 0110BCD= 86 10

    b) 0011 0101 0001

    3 5 1

    0011 0101 0001BCD= 35110

  • 8/12/2019 Basic Digital Electronics - Unit 2

    25/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201037

    2.10 ADD BCD NUMBERS

    BCD is a numerical code and can be used in arithmetic operation. Addition is the

    most important operation because the other three operations (subtraction,

    multiplication and division) can be accomplished by the use of addition.

    Step Procedure To Add BCD Number

    Step 1: Add the two BCD number using rules for binary addition.

    Step 2: if a 4-bit sum is equal or less than 9, it is a valid BCD number.

    Step 3: if a 4-bit sum is greater than 9, or if a carry out of the 4-bit group is

    generated, it is an invalid result. Add 6 (0110) to the 4-bit sum in order

    to skip the six invalid states and return the code to BCD. If a carry

    result when 6 is added, simply add the carry to the next 4-bit group.

    Example 1 :

    Add the following BCD numbers:

    a. 0011 + 01000 0 1 1

    + 0 1 0 00 1 1 1

    b. 0010 0011 + 0001 01011 1 1

    0 0 1 0 0 0 1 1+ 0 0 0 1 0 1 0 1

    0 0 1 1 1 0 0 0

  • 8/12/2019 Basic Digital Electronics - Unit 2

    26/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    c. 1000 0110 + 0001 00111 1

    1 0 0 0 0 1 1 0+ 0 0 0 1 0 0 1 11 0 0 1 1 0 0 1

    d. 0100 0101 0000 + 0100 0001 01111 1

    0 1 0 0 0 1 0 1 0 0 0 0+ 0 1 0 0 0 0 0 1 0 1 1 11 0 0 0 0 1 1 0 0 1 1 1

    Example 2:

    Add the following BCD numbers:

    a. 1001 + 0100

    1 0 0 1+ 0 1 0 01 1 0 1 Invalid BCD number (>9)+ 0 1 1 0 Add 0110 (6)0 0 0 1 0 0 1 1

    1 3

    b. 1001 + 1001

    1

    1 0 0 1+ 1 0 0 11 0 0 1 0 Invalid because of carry+ 0 1 1 0 Add 0110 (6)0 0 0 1 1 0 0 01 8

    Fatma Syazana Zaini,

    IKM Besut, 201038

  • 8/12/2019 Basic Digital Electronics - Unit 2

    27/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    c. 0001 0110 + 0001 0101

    1 10 0 0 1 0 1 1 0+ 0 0 0 1 0 1 0 10 0 1 0 1 0 1 1 Right group is invalid (>9),left group is valid+ 0 1 1 0 Add 0110 (6)0 0 1 1 0 0 0 1

    3 1

    d. 0110 0111 + 0101 0011

    1 1 1 10 1 1 0 0 1 1 1+ 0 1 0 1 0 0 1 11 0 1 1 1 0 1 0 Both groups areinvalid (>9)+ 0 1 1 0 0 1 1 0 Add 0110 (6) to bothgroup0 0 0 1 0 0 1 0 0 0 0 0

    1 2 0

    Fatma Syazana Zaini,

    IKM Besut, 201039

  • 8/12/2019 Basic Digital Electronics - Unit 2

    28/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201040

    2.11 GRAY AND ASCII CODES

    THE GRAY CODES

    There are many specialized codes used in digital systems. Some codes arestrictly numeric like BCD and others are alphanumeric that is they used torepresent numbers, letters, symbols and instructions. The code introduced inthis topic is the Gray code.

    The Gray Code is un-weighted and is not an arithmetic code: that is there areno specific weights assigned to the bit positions. The important feature of theGray code is that it exhibits only a single bit change from one code word tothe next in sequence.

    This property is important in many applications, such as shaft positionencoders, where error susceptibility increases with the number of bit changesbetween adjacent numbers in a sequence.

    Table 4 is a listing of the 4-bit Gray code for decimal numbers 0 through 15.Binary numbers are shown in the table 4 for reference.

    DECIMAL BINARY GRAY CODE

    0 0000 0000

    1 0001 00012 0010 00113 0011 00104 0100 01105 0101 01116 0110 01017 0111 01008 1000 11009 1001 110110 1010 1111

    11 1011 111012 1100 101013 1101 101114 1110 100115 1111 1000

    Table 4

  • 8/12/2019 Basic Digital Electronics - Unit 2

    29/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    BINARY TO GRAY CODE CONVERSION

    Procedure:

    i. The most significant bit (left-most) is the Gray code is the same as thecorresponding MSB in the binary number.

    ii. Going from left to right, add each adjacent pair of binary code bits to get thenext Gray code bit. Discard carries.

    Example 1:

    Convert the binary number 10110 to Gray code.

    1 + 0 + 1 + 1 + 0 Binary1 1 1 0 1 Gray

    Example 2:

    Convert the binary number 1100 0110 to Gray code

    1 + 1 + 0 + 0 + 0 + 1 + 1 + 0 Binary1 0 1 0 0 1 0 1 Gray

    GRAY TO BINARY CONVERSION

    Procedure:

    i. The most significant bit (left-most) in the binary code is the same as thecorresponding bit in the Gray code.

    ii. Add each binary code bit generated to the Gray code bit in the next adjacentposition. Discard carries.

    Fatma Syazana Zaini,

    IKM Besut, 201041

  • 8/12/2019 Basic Digital Electronics - Unit 2

    30/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Example1:

    Convert the Gray code below to binary.

    a. 11011

    Fatma Syazana Zaini,

    IKM Besut, 201042

    b. 1011 1111

    ASCII CODES

    ASCII is the abbreviation for American Standard Code for Information

    Interchange. Pronounce askee. ASCII is a universally accepted alphanumeric

    code used in most computers and other electronic equipment. Most computer

    keyboards are standardized with the ASCII. When we enter a letter, anumber or control command, the corresponding ASCII code goes into the

    computer.

    ASCII has 128 characters and symbols represented by a 7-bit binary code.

    Actually ASCII can be considered an 8-bit code with the MSB always 0. This

    8-bit code is 00 through 7F in hexadecimal.

    The first thirty-two ASCII characters are non-graphic commands that are

    never printed or displayed and are used only for control purposes.

    Examples of the control characters are null, line feed, start of text and

    escape. The other characters are graphic symbols that can be printed or

    displayed and include the letters of the alphabet (lowercase and uppercase),

    the ten decimal digits, punctuation signs and other commonly used symbols.

  • 8/12/2019 Basic Digital Electronics - Unit 2

    31/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Table 5 is a listing of the ASCII code showing the decimal, hexadecimal and

    binary representations for each character and symbol. The left section of the

    table lists the names of the 32-control character (00 through 1F

    hexadecimal).

    Table 5

    The first thirty-two codes in the ASCII table represent the control

    characters. These are used to allow devices such as a computer and printer tocommunicate with each other when passing information and data.

    Table 2 lists the control characters and the control key function that allowsthem to be entered directly from an ASCII keyboard by pressing the controlkey (CTRL) and the corresponding symbol.

    Fatma Syazana Zaini,

    IKM Besut, 201043

  • 8/12/2019 Basic Digital Electronics - Unit 2

    32/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201044

    The extended ASCII contains characters in the following general categories:

    a. Foreign (non-English) alphabetic charactersb. Foreign currency symbolsc. Greek Letter

    d. Mathematical symbolse. Drawing charactersf. Bar graphing charactersg. Shading character

    Example 1:

    Determine the binary ASCII codes that are entered from the computers keyboardwhen the following BASIC program statement is typed in also express each code inhexadecimal.

    20 PRINT A= ; X

    Solution;

    The ASCII code for each symbol is found in table 1.

    Symbol Binary Hexadecimal

    2 011 0010 3216

    0 011 0000 3016Space 010 0000 2016P 101 0000 5016R 101 0010 5216I 100 1001 4916N 100 1110 4E16T 101 0100 5416Space 010 0000 2016 010 0010 2216A 100 0001 41

    16

    = 011 1101 3D16 010 0010 2216; 011 1011 3B16X 101 1000 5816

  • 8/12/2019 Basic Digital Electronics - Unit 2

    33/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201045

  • 8/12/2019 Basic Digital Electronics - Unit 2

    34/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201046

    SUMMARY

    In this topic, students have learned the numeric quantities occur naturally in analogue butmust be converted to digital form to be used by computers or digital circuitry.

    Student must understand that the binary numbering system is used in digital systemsbecause the 1s and 0s are easily represented by ON or OFF transistors, which output0volt for zero(0) and 5volt for one(1).

    Students also must know that the ASCII is used by computers to represent all letters,numbers and symbols in digital form.

    EXERCISE

    1. Convert each decimal number to binary.a. 23b. 57

    c. 45

    2. Convert the following binary to decimala. 101102b. 1101 10112c. 110 11112d. 1001 11012

    3. Determine the 1s complement of each binary number:a. 0001 1010

    b. 1111 0111c. 1000 1101

    4. Determine the 2s complement of each binary number:a. 0001 0110b. 1111 1100c. 1001 0001

  • 8/12/2019 Basic Digital Electronics - Unit 2

    35/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    Fatma Syazana Zaini,

    IKM Besut, 201047

    5. Using the rules for binary addition, evaluate the followinga. 11112+ 1002b. 01112+ 10102c. 11002+ 0102

    6. Using the rules for binary subtraction evaluate the following.a. 10002 00112b. 01012 00102c. 11112- 11002

    7. Multiply 0111 1111 by 0000 0101.

    8. Convert the following decimal numbers to binary:a. 468

    b. 7238c. 56248

    9. Convert the following binary numbers to octal:a. 1 1010 11112b. 10 0110 00102c. 101 1111 10012

    10.Convert the following decimal numbers to BCD:a. 6

    b. 15c. 273d. 849

    11. What decimal numbers are represented by each BCD code?a. 1000 10012b. 0010 0111 10002c. 0001 0101 01112

    12.Convert the following binary numbers to the Gray code:

    a. 11002b. 10102c. 110102

  • 8/12/2019 Basic Digital Electronics - Unit 2

    36/36

    UNIT 2: NUMBER SYSTEMS AND CODES

    13.Convert the following Gray codes to binary:a. 10002b. 10102

    c. 111012

    14.What is the ASCII representation for each of the following characters?Express each as a bit and in hexadecimal notation.

    a. Kb. rc. $d. +

    REFERENCES

    1. Digital System Principle And Applications, Tocci, R.J, Prentice Hall international

    2. Digital Fundamentals, Floyd T.L, Merrill Publishing

    3. BPL(K) Module TFV 2033 Digital Electronics 1

    4. Digital Electronics: Teaching Module, KUITHO