Docsity

Arithmetic Operators - Introduction to Logic Design - Lecture Slides, Slides of Digital Logic Design and Programming

Partial preview of the text

Download Arithmetic Operators - Introduction to Logic Design - Lecture Slides and more Slides Digital Logic Design and Programming in PDF only on Docsity!

Arithmetic Operators

Decimal Codes

Class 2 outline

  • Number Ranges
  • Arithmetic Operators
  • Decimal Codes
  • Material from sections 1-3 and 1-4 of text

Numbers ranges with binary

  • With 1 bit โ€“ 2^1 = 2 numbers
    • 0 and 1
  • With 2 bits โ€“ 2^2 = 4 numbers
    • 0, 1, 2, 3 (00, 01, 10, 11)
    • Or in fixed point 0, .5, 1, 1.
    • Or in fractional 0, .25, .5,.
  • With 3 bits โ€“ 2^3 = 8 numbers (Octal)
    • 0,1,2,3,4,5,6, (000,001,010,011,100,101,110,111)

Other number ranges

  • With 4 bits โ€“ Hex โ€“ 2^4 = 16 numbers
    • 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  • With 8 bits โ€“ 256 โ€“ commonly referred to as a

byte

  • 0 through (2^8 -1), or 0 through 255
  • With 16 bits
  • 0 through (2^16 -1), or 0 through 65,535 if the 16 bits represent and unsigned number

Addition

  • Basic โ€“ consider the bit by bit possibilities
    • Augend 0 0 1 1
    • Addend 0 1 0 1
    • Sum 0 1 1 10
  • And including a carry
    • Carry 0 0 0 0 1 1 1 1
    • Augend 0 0 1 1 0 0 1 1
    • Addend 0 1 0 1 0 1 0 1
    • Sum 0 1 1 10 1 10 10 11

Result carry

  • For those instances where the result was 10 or

11, the msb 1 of this addition are a carry into

the next bit position.

  • Muti-bit example
    • Carries
    • Augend 01100 12
    • Addend 00101 5
    • Sum 10001 17

Binary Subtraction

  • Just like subtraction in any other base
    • Minuend 10110
    • Subtrahand - 10010
    • Difference 00100
  • And when a borrow is needed. Note that the

borrow gives us 2 in the current bit position.

Binary subtraction (cont)

  • And more ripple -

Operations in other bases

  • Operations in octal and hex follow the same

rules.

  • Book provides and example of octal

multiplication

Conversion from Decimal

  • To binary (the most common)
    • Have seen one method so far
  • A General Procedure
    • Step 1 โ€“ Separate into integer and fractional parts if there is a binary point
    • Repeat: Divide by radix, r, until remainder is <r
    • The final remainder is the msb.

Another example

  • Convert 42 10 to binary
  • Book also show fractional conversion

Decimal codes

  • We are cavemen at heart and like base 10.
  • Computer electronics are such that it likes

base 2.

  • IS THERE A COMPROMISE?
    • Binary Coded Decimal (BCD)
    • Group the binary into groups of 4 bits. Each group can represent 16 distinct symbols. Use only the 10 digits.

Another example

  • 46 + 68
  • Encode as BCD digits
    • 46 = 0100 0110
    • 68 = 0110 1000
  • Simply do the binary addition of each BCD

digit

  • ?? = 1010 1110 but both are out of the useable BCD representation range

What to do?

  • Starting with least significant digit add 6
    • Had the bcd representation 1010 1110
    • Add 6 or 0110
    • to the 1110
    • Getting 10100 and have BCD digit 0100 and a carry to the next BCD position
  • WHY 6?