1 - Binary_Systems

Embed Size (px)

Citation preview

  • Chapter 1

    1

    Chapter 1

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy

  • One characteristic of digital system is their ability to manipulate discrete elements of information

    The signals in most present day electronic digital system use just two discrete values and The signals in most present day electronic digital system use just two discrete values and said to be Binary

    A Binary Digit is called a Bit

    A Bit has two values: 0 or 1

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 2

  • A group of bits can be made to represent discrete symbols

    A digital system is a system that manipulates discrete elements of information that is represented internally in Binary formatdiscrete elements of information that is represented internally in Binary format

    Most digital devices are programmable

    Digital system manipulates discrete quantities of information that are represented in binary form

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 3

  • There are different base systems:

    Base 2 (Binary)

    Base 3

    Base 4

    Base 5

    Base 6

    Base 7

    Base 8 (Octal)

    ..

    Base 16 (Hexadecimal)

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 4

  • Base 2: Bnary: 0, 1

    Base 8: Octal: 0, 1, 2, 3, 4, 5, 6, 7

    Base 10: Decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Base 10: Decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

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

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 5

  • Decimal BaseDecimal Base BinaryBinary((Base Base 22))

    Octal Octal ((Base Base 88))

    HexadecimalHexadecimal((base base 1616))

    0000 00 00 000101 11 11 110202 1010 22 220303 1111 33 330404 100100 44 440505 101101 55 550505 101101 55 550606 110110 66 660707 111111 77 770808 10001000 1010 880909 10011001 1111 991010 10101010 1212 AA1111 10111011 1313 BB1212 11001100 1414 CC1313 11011101 1515 DD1414 11101110 1616 EE1515 11111111 1717 FF

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 6

  • A decimal number of 7,392 represents a quantity equal to 7 thousand, plus 3 hundreds, plus 9 tens, plus 2 units

    7 X 103 + 3 X 102 + 9 X 101 + 2 X 1007 X 103 + 3 X 102 + 9 X 101 + 2 X 100

    In more general termsa5a4a3a2a1a0.a-1a-2a-3

    =105 a5 + 104 a4 + 10

    3 a3 + 102 a2 + 10

    1 a1 + 100 a0

    + 10-1 a-1 + 10-2 a-2 + 10

    -3 a-3

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 7

  • The decimal number system is said to be of base 10 or Radix 10 Because it uses 10 digital and the coefficients are multiplied by powers of 10

    The Binary system is a different number The Binary system is a different number system. The coefficients of the Binary number system have only two possible values: 0 and 1. Each coefficient ai is a multiple of 2

    i

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 8

  • General Rules:

    A number expressed in a baser system has coefficients multiplied by power of r

    an . rn + an-1. r

    n-1 + ..+ a2 . r2 + a1 . r

    1 + a0 + a-1. r-1 + a-an . r

    n + an-1. rn-1 + ..+ a2 . r

    2 + a1 . r1 + a0 + a-1. r

    -1 + a-2 . r

    -2 + .. + a-m . r-m

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 9

  • There are three major number manipulations:

    1. Convert from any base to decimal.

    2. Convert from decimal to any base.

    3. Convert from any base to any base.

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 10

  • Example,

    (11010.11)2 is a binary number

    Q: What is the decimal equivalent to this number?number?

    A: 24 X 1 + 23 X 1 + 22 X 0 + 21 X 1 + 20 X 0 + 2-1 X 1 + 2-2 X 1 = 26.75

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 11

  • Exercise:

    What is the equivalent decimal number for (4021.2)5 ; a number is given in base 5

    What is the equivalent decimal number for (127.4)8 ; a number given in base 8

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 12

  • Exercise:

    What is the equivalent decimal number for (B65F)H ; a number is given in base 16

    What is the equivalent decimal number for (110101)2; a number given in base 2

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 13

  • Suppose we want to convert a number in base 10 to binary or other bases. What do we do?

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 14

  • Converting from decimal to Binary & Octal

    Steps:1. Divide the decimal by 2 until we reach a 0

    2. The reminder is the new binary number

    ReminderReminderReminderReminder4141 22 112020 22 001010 22 00

    55 22 1122 22 0011 22 1100

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 15

    (41)d = (101001)2

  • Example:

    Convert decimal 153 to Octal

    ReminderReminder153153 88 11

    1919 88 3322 88 2200

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 16

    (153)d = (231)8

  • Converting a fraction Steps:1. Multiply the Fraction by 2

    2. The whole number is the new binary number

    Whole NumberWhole Number00..68756875X X 22

    11

    00..375375X X 22

    00

    00..750750X X 22

    11

    00..500500X X 22

    11

    00..0000University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 17

    (0.6875)d = (0.1011)2

  • Example,

    Convert (0.513)10 to Octal

    Whole NumberWhole Number00..513513X X 88

    44

    00..104104X X 88

    00

    00..832832X X 88

    66

    00..656656X X 88

    55

    00..248248 11University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 18

    (0.513)d = (0.406517)8

  • Converting from Binary to Octal & Hex

    Steps:1. Group the n bits of Binary and directly converting them

    Example: Q: Convert the following Binary to Octal Q: Convert the following Binary to Octal

    & Hex (10110001101011.111100000110)2 A: Group each three bits and find their Octal equivalence

    (26153.7406)8 A: Group each four bits and find their Hex equivalence

    (2C6B.F06)H

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 19

  • Converting from Octal & Hex to DecimalSteps:

    1. Directly convert each bit to its Octal and Hex equivalence

    Example: Example:

    Convert the following Octal Number to its Binary (673.124)8 = (110 111 011.001010100)2

    Convert the following Hex Number to its Binary(306.D)H = (0011 0000 0110. 1101)2

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 20

  • Determine the base of the numbers in each of the following operations:

    24 + 17 = 40

    14/2 =5

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 21

  • 54/4 = 13

    7 + 12 = 19

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 22

  • There are two types of complements for each base-r system: the radix complement and the diminished radix complement.

    rs complement: Radix Complementrs complement: Radix Complement(r-1)s complement: Diminished Radix Complement

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 23

  • 9s complement: Obtained by subtracting each digit from 9

    Example: 1. 9s complement 546700 is 999999

    - 546700- 546700---------------453299

    2. 9s complement 012398 is 999999- 012398

    ----------------987601

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 24

  • 1s Complement: Obtained by Subtracting each digit from 1.

    Example:1. 1s complement 1011000 is 1111111

    - 1011000- 1011000---------------0100111

    2. 1s complement 0101101 is 1111111- 0101101

    -------------------1010010

    Simply convert each 0 to 1 and each 1 to 0

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 25

  • Radix Complement: 10s complement is 9s complement +1 2s complement is 1s complement +1

    Example: 10s complement of 2389 = 9999

    - 2389 -----------7610

    -----------7610

    + 1

    2s complement of 1101101 is 0010010+ 1-----------------

    0010011

    Hint: for 2s complement, leave all significant 0s unchanged until the first 1 and then flip each 0 to 1 and each 1 to 0

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 26

  • Find the 10s complement of (4567)d

    Find the 2s complement of (10101011)

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 27

  • RULE:

    1. Add M to the rs complement of NM + (rn N) = M N + rn

    2. If M > N , the sum will produce an end carry, rn, which can be discardedwhich can be discarded

    3. If M < N, the sum does not produce an end carry and is equal to rn (N-M) which is the rs complement of (N M). To obtain the answer in a familiar form, take the rs complement of the sum.

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 28

  • M N = (72532)10 (3250)10

    M = 72532N = + 96750

    ----------------------------------1 69282

    - 1 00000-------------------

    69282

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 29

  • Exercise:

    Using 10s complement perform the subtraction 3250 72532

    Using 2s complement perform the subtraction 1010100 - 1000011

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 30

  • Exercise:

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 31

  • There are two types of numbers:

    Un-signed:

    All positive quantities

    Signed:

    Some positive and some negative Some positive and some negative

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 32

  • Usually a negative numbers are represented by () minus sign

    In computer language this is really hard

    To represent a negative number assign the To represent a negative number assign the Most Significant Bit (MSB) to 1.

    If MSB is = 0, then the number is positive

    If MSB is = 1, then the number is negative

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 33

  • There are many representations for the signed-numbers in binary.

    Most popular ones are:-

    Signed-magnitude representationSigned-magnitude representation

    Signed-2s-complement representation

    In ALL presentations MSB SHOULD be:-

    1 for negative numbers

    0 for positive numbers

    In computers signed numbers are presented using signed-2s-complement format

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 34

  • It is used in some ordinary arithmetic operations but not in the computer arithmetic

    N bits

    Represent decimal 5 & -5 in 4-bits signed-magnitude

    (5)10 -> (0101)2 (-5)10 -> (1101)2

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 35

    1 bit N-1 bits

    Sign bit Magnitude bits

  • Decimal BaseDecimal Base SignedSigned--22s s ComplementComplement

    Signed Signed MagnitudeMagnitude

    ++77 01110111 01110111++66 01100110 01100110++55 01010101 01010101++44 01000100 01000100++33 00110011 00110011++22 00100010 00100010++22 00100010 00100010++11 00010001 00010001

    00 00000000 00000000--11 11111111 10011001--22 11101110 10101010--33 11011101 10111011--44 11001100 11001100--55 10111011 11011101--66 10101010 11101110--77 10011001 11111111--88 10001000 ----------

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 36

  • Exercise:

    find the decimal for the following8-bit signed binary number in signed-2s-complement representation

    (10110010)2

    (11110110)2

    (00110010)2

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 37

  • Anytime we add two signed or unsigned numbers we may get an overflow.an overflow.

    Overflow unsigned

    Overflow signed

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 38

  • Overflow occurs when we start with n-bits and the result occupies n+1 bits.

    We just add another 0 to a positive number or another 1 to a negative number in the most-significant position to extend them to n+1 bits another 1 to a negative number in the most-significant position to extend them to n+1 bits and then perform the addition.

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 39

  • If the Carry-in to the MSB (sign bit) is different than the carry-out of MSB (sign bit), then there is an overflow

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 40

  • Exercise: perform the following addition (signed numbers)

    --6 1111 10106 1111 1010++13 0000 110113 0000 1101------------------------------------------

    ++6 0000 01106 0000 0110++13 0000 110113 0000 1101------------------------------------------ ------------------------------------------------------------------------------------

    --6 1111 10106 1111 1010--13 1111 001113 1111 0011------------------------------------------

    ++6 0000 01106 0000 0110--13 1111 001113 1111 0011------------------------------------------

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 41

  • An n-bit Binary Code is a group of n bits that assume 2n distinct combination

    If n = 2, 22 =4 distinct combinations

    If n = 3, 23 = 8 distinct combinations If n = 3, 2 = 8 distinct combinations

    If n = 4, 24 = 16 distinct combinations

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 42

  • BCD Code: Binary Coded Decimal Code

    BCD DigitBCD Digit Decimal SymbolDecimal Symbol00000000 0000010001 1100100010 2200110011 3300110011 3301000100 4401010101 5501100110 6601110111 7710001000 8810011001 99

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 43

  • ASCII Codes:American Standard Code of Information Interchange

    Uses seven bits to code 128 characterUses seven bits to code 128 character

    Look book page 23

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 44

  • Other decimal codes

    Look at book page 24 table 1.7

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 45

  • Binary Logic is based on Binary System

    Holds one of two values: 0 and 1 (true, false) (yes, no)..etc

    Def: Variables A,B,C, y,y,z etc. Variables A,B,C, y,y,z etc.

    These variables can hold one of two values: 0, 1

    Three basic logical operations: AND, OR, NOT

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 46

  • 1. AND: represented by .x . y = z or xy = z z = 1 if and only if both x=1 and y=1 otherwise z=0

    2. OR: represented by +2. OR: represented by +x + y = z z = 1 if either x=1 or y = 1 otherwise z=0

    3. NOT: x = z z= 1 if x = 0 other wise z=0

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 47

  • Truth Table for AND, OR, and NOT

    ANDAND OROR NOTNOTxx yy xyxy xx yy x+yx+y xx xx

    00 00 00 00 00 00 00 11

    00 11 00 00 11 11 11 00

    11 00 00 11 00 11

    11 11 11 11 11 11

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 48

  • 2-input AND gate

    2-input OR gate

    Not gate Not gate

    3-input AND gate

    3-input OR gate

    University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 49