انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

complement and binary codes

Share |
الكلية كلية العلوم للبنات     القسم قسم الحاسبات     المرحلة 1
أستاذ المادة احمد محمد شهاب المطيري       3/22/2011 12:45:08 PM

Babylon University

 

The college of science for girls

 

Logic Design

 

Lecture 2

 

Complements:

 

   They are used in digital computers for simplifying the subtraction for logical manipulation , there are 1 s complement & 2 s complement .

 

 

1) 1 s complement:-

 

    The 1 s complement of binary number obtained changing (0 to 1) each (1 to 0) for example (1010)   (0101).

 

 

2) 2;s complement :-

 

    The 2 s complement of Binary number obtained by adding 1 to 1 s complement .

 

                    2 s complement = 1,s complement + 1

 

 

 For example :-find the 2 s complement for:                                                                    1) (1110)                                            2) (10110)        

 

 

2 s complement

 


1) (1110)    (0001)  + 1 = (0010)  

 

2) (10110)   (01001)  + 1 = (01010)

 

 

How can we use complement to do complements?

 

We use it if we are subtract a large number from a smaller number .

 

 

1 s complement :-

 

 

        Direct                                                                           1 s complement

 

      1 1 0 0 1                                                                              1 1 0 0 1

 

 

carry

     -  1 0 0 1 1                                                                           + 0 1 1 0 0

 

       0 0 1 1 0                                                                           1 0 0  1 0 1

 

                                                                                                                 1 +          

 

                                                                                                  0 0 1 1 0

 

We did the subtraction as follows :-

 

1) Determine the 1 s complement of the small number .

 

2) Add 1 s complement to the small number .

 

3) The last carry is 1 when ever three is a 1 carry in the last position. Remove it an

 

     add it to the result we called this end-around carry

 

 

       Direct                                                                             1 s complement

 

      1 1 1 1                                                                               1 1 1 1

 

        1 1 0 1 -                                                                             0 0 1 0 +

 

      0 0 1 0                                                                            1 0 0 0 1

 

                                                                                                           1 +

 

                                                                                                 0 0 1 0

 

 

Ahmed M. Shhaab

 

Example:-

 

 

               1 0 0 1                                                     1 0 0 1

 

               - 1 1 0 1                                                 +  0 0 1 0

 

                0 1 0 0                                                     1 0 1 1                - 0100

 

 

From example above

 

There is no carry (no end around carry)

 

1) as in this case the answer is negative and in 1 s complement form

 

2) we take the 1 s complement of the result and change the sign .

 

 

Example:-

 

 

          0 1 1 0 1                                                       0 1 1 0 1

 

           - 1 1 0 1 1                                                   +  0 0 1 0 0

 

         - 0 1 1 1 0                                                       1 0 0 0 1           -01110

 

 

No carry

    

 

 

 

2 s complement:-  subtraction by 2 s complement

 

 

* subtract small number from large one

 

        Direct                                                          2 s comp. method                                                                  

 

        1 1 0 0                                                                 1 1 0 0           

 

 

carry

          1 0 1 1                                                              + 0 1 0 1

 

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

 

                                                                                               We discard the final carry

 

 

*subtraction of the large from smaller number

 

         Direct                                                        2 s comp. method

 

        1 0 0 1 1                                                          1 0 0 1 1

 

       -  1 1 1 0 0                                                       + 0 0 1 0 0

 

      -  0 1 0 0 1                                                          1 0 1 1 1

 

   

 

                                                                               There is no carry

 

Therefore:- we convert this number to 1 s complement by subtract one from the result then we change the result by taking the 1;s complement to it and then put the negative sign .

 

        1 0 1 1 1

 

       -             1

 

        1 0 1 1 0    0 1 0 0 1

 

                                             = -  1 0 0 1

 

Example:-

 

           Direct

 

         1 0 0 0 1                                                     1 0 0 0 1

 

         - 1 0 1 0 0                                                     0 1 1 0 0    2 s comp.

 

       - 0 0 0 1 1                                                    1 1 1 0 1

 

 

1 s comp.

                                                                          -             1 

 

 

Ahmed M. Shhaab

 

                                                                           1 1 1 0 0                       - 0 0 0 11

 

 

Binary Codes:

 

    A binary number of n digital may be represented by n binary circuit elements ,each having an output signal equivalent to a 0 or 1 . Digital systems represent and process not only binary numbers .But also many other discrete elements of information .

 

Any discrete element of information among group of quantities can be represented by a binary code.

 

For example:- red is one distinct color of the spectrum , the letter A is one distinct letter of the alphabet

 

 

1) Decimal codes:                 

 

      Numbers are represented in digital computers either in binary or in decimal through a binary code . the input decimal numbers are stored internally in the computer by means of a decimal code , there are many codes that are used to represent decimal numbers such as :-

 

 

a) Binary Coded Decimal ( B C D or 8421 code )

 

    it is the most widely used code to represents decimal numbers. The weights of the BCD are 8421. to encoded any decimal number in BCD simply replace each decimal digit with the appropriate decimal digit to each group.

 

 

Example:-  Encoded each of the following decimal number in BCD code ?

 

                    ( 3 )       ,          ( 9.2)            ,           (150)               ,   (65)

 

                  (0011)         (1001.0010)       (000101010000)     (01100101)

 

 

The reverse process is called decode which return the coded number into its decimal equivalent is done by grouping each 4-bits (from the LSB to MSB) and assigning the appropriate decimal digit to each group.

 

 

 

Example:-  Decode each of the following BCD numbers ?

 

                             ( 1 0 0 0  0 1 1 0)        ,       ( 1 0 0 1  0 1 1 1  0 1 0 0 )

 

 

                     ( 8             6 )                           ( 9           7            9 )

 

 

b) The Excess -3 Code

 

    Encoding the decimal numbers in excess-3 code is done Either by encoding each decimal digit in BCD then adding (3) To each digit as follows:-

 

 

 

      ( 7 5 )                                                          ( 9.8 )

 

     ( 0 1 1 1    0 1 0 1 )                               (1 0 0 1 .  1 0 0 0 )

 

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

 

    (  1 0 1 0 1 0 0 0 )                                (1 1 0 0 . 1 0 1 1)

 

 

Or  by adding 3 To each decimal digit then converting each one to binary as follows

 

     ( 7  5 )                                                         ( 9 . 8)

 

        3+ 3+                                                             3+ 3+ 

 

     10 8                                                               12 . 11

 

 

Ahmed M, Shhaab

 

(10101000)                                             (1100 . 1011)

 

the decoding process is the reverse

 

    (10101000)                                           (01000011)

 

      10      8                                                             4       3

 

      3-      3-                                                            3-      3-

 

    ( 7       5 )                                                      ( 1       0 )

 

     = (75)                                                              = (10)

 

 

c) The Gray Code ( reflected code )

 

     the Gray code is an un weight code ; that is there are no specific weights assigned to the bit positions. The important feature of the Gray code is that it exhibits only a single bit change fro one code number to the next

 

 

To encode any decimal number in Gray code follows these steps :-

 

1)      convert the decimal number into binary.

 

2)      The MSB of the binary number is the same in the Gray code.

 

3)      Going from MSB to LSB add each adjacent bits to get the next Gray code bit (Discard carries)

 

 

Example:-  Encode the following number in binary ?

 

 

   

LSB

÷ 2    23                                        ( 2 3 )  

 

          11    1                                 

 

               5     1                                  (1 0 1 1 1 )

 

          2     1

 

 

MSB

          1     0                                 ( 1 1 1 0 0 )

 

 

 

                 ( A . 6 )                                           ( 1 0 1 0 . 0 1 1 0 )

 

 

 ( 1 0 10 . 0 1 1 0 )

 

                                                                ( 1 1 1 1 . 0 1 0 1 )

 

 

Example:-  Decode the following coded numbers

 

 

 

                 1)   ( 1  0  0  0  1  0  1  1  0 )

 

  

 

 

 

      (  1 1  1  1  0  0  1  0  0 )

 

 

               2)  (  0  1  1  1  0  1 . 1  0 )

 

 

 

 

 

Ahmed M, Shhaab

 

    (   0  1  0  1  1  0 . 1  1 )

 

 

  Decimal

 

  Binary

 

    BCD

 

  Excess-3

 

  Gray

 

    0

 

    1

 

    2   

 

    3

 

    4

 

    5

 

    6

 

    7

 

    8

 

    9

 

   10

 

  0

 

  1

 

  10

 

  11

 

  100

 

  101

 

  110

 

  111

 

  1000

 

  1001

 

  1010

 

    0000

 

    0001

 

    0010

 

    0011

 

    0100

 

    0101

 

    0110

 

    0111

 

    1000

 

    1001

 

    00010000

 

    0011

 

    0100

 

    0101

 

    0110

 

    0111

 

    1000

 

    1001

 

    1010

 

    1011

 

    1100

 

    01000011

 

    0

 

    1

 

    11

 

    10

 

    110

 

    111

 

    101

 

    100

 

    1100

 

    1101

 

    1111

 

 

 

2) Error Detection Codes:-

 

    An error detection code can be used to detect errors during an additional bit to the massage of each information .

 

This bit is called a parity bit

 

Therefore a parity bit is an extra bit included with a massage to make the Total number of 1 s either odd or even .

 

 

There are two types of parity:

 

1) Odd parity:- add bit to the massage (0 or 1) so that the Total number of 1 s become

 

                          Odd

 

 

2) Even parity:- add bit to the massage (0 or 1) so that the Total number of 1 s become

 

                           Even

 

 

 Massage

 

 Odd

 

 parity

 

  Even

 

 parity

 

 0000000

 

 1011101

 

 1011100

 

 1111111

 

     1

 

     0

 

     1

 

     0

 

     0

 

     1

 

     0

 

     1

 

 

2) Alphanumeric Codes:-

 

    Many application of digital computers require the handling of  data that consist not only of numbers , but also of letters . An  alphanumeric code is a binary code of a group of elements consisting of the ten decimal digits (0-9), the alphabetical letters (A-Z , a-z ) the arithmetic operations(+, - , * , ÷ , % , > , = , < , …..etc) and also some special symbols such as (& , # , @ ,…etc) .

 

An example of such a code is ASCII code (American Standard Code Information Interchange) ; which consist of seven bits plus a parity bit .

 

 

 

  

 

 

Ahmed M. Shhaab

 

Binary Logic

 

        Binary Logic is used to describe , in a mathematical way, the manipulation and processing of binary information .

 

Binary logic is consists of binary variables and Logical operation .

 

The binary variables are letters of alphabet such as A , B , C , X , Y ,…etc. with each variable having two and only two distinct possible values {0 , 1}.

 

 

The logical operations are the three basic operations: AND , OR and NOT.

 

  Logical

 

 Operations

 

   Symbol                    Truth Table

 

  Reading

 

 

 

    AND

 

 

 

   1)  .        x.y=z

 

   2)           xy=z

 

x     y

 

x.y

 

   

 

X and Y 

 

equal Z  

 

0     0

 

0     1

 

1     0

 

1     1

 

 0

 

 0

 

 0

 

 1

 

 

     

 

    OR

 

 

 

 

 

  +         x+y=z

 

x     y

 

x+y

 

 

 X or Y

 

equal Z

 

0     0

 

0     1

 

1     0

 

1     1

 

  0

 

  1

 

  1

 

  1

 

 

    NOT

 

 

 

   1) ~        x~=z

 

   2) `         x`=z

 

   x

 

  x`

 

 

  X not

 

equal z

 

  0

 

  1

 

  1

 

  0

 

 

 

Not:- Binary Logic and Binary arithmetic have some similar in its operations and also the symbol used for AND and OR . however binary logic should not be confused with binary arithmetic.

 

 

- A Truth Table:- is a table of all possible combinations ( 2 . n=number of variables) of the variables showing the relation between the values that the variables may take and the result of the operation .

 

 

 

It is possible to describe the operation of the AND and OR with an electronic digital circuits and as shown below.

 

 

 

B

 

 

A

 

  

 

              

0

0

1

   

Z

 

 

 

 

 

 

 

 


                        Z = A . B  ( logic AND )

 

 

 

Ahmed M. Shhaab

 

 

          

Z

 

          

A

 

 

B

 

1

 

 

1

 

0

 

 

0

 

                                                                                                                                                                

 

 

 

 

 

 

 

                                   Z = A + B ( logic OR )

 

 

          

Z

 

                     

A

 

Relay

 

 

 

 

 

 

 

 

 

 


                                    Z = A`  ( logic NOT )

 

 

Basic Logic Gates:

 

        Logic circuits that perform the Logical operations of AND , OR and NOT are called Gates or Logic Gates . it is a block of a hardware that produce Logic-1 or Logic-0 output signal if input Logic requirements are satisfied . the three basic logic gates are :-

 

    

x

 

y

 

 

z = x . y    2-input AND gate

 

 


1- AND Gates       

 

 

 

    

x

 

y

 

 

z = x + y    2-input OR gate

 

 


2-OR Gates

 

 

 

 

    

z = x`   NOT gate  ( inverter )

 

x

 

3- NOT Gates 

 

 

 

 

Pulse Waveforms:

 

     Pulses are very important in digital circuits and systems because voltage levels are normally changing back and forth between the high ( logic-1 ) and low ( logic-0 )

 

           

High

 

 

Low

 

Low

 

High

 

 

Rising edge

 

Falling edge edge

Falling edge

Rising edge

  

( positive going pulse )

 

 

 

( negative going pulse )

 


      

 

 

 

 

 

 

 

 

Ahmed M. Shhaab

 

                                                                                                                                                                       

 

 


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
الرجوع الى لوحة التحكم