Digital Design



Download 0.78 Mb.
Date26.10.2023
Size0.78 Mb.
#62417
Lecture 2-Fall23 (1)

Logic Design CSCI 221

Lecture 2

Arithmetic Operations

  • Subtraction

Base : 10
8
0
1
1
Base : 2
0
z
1
1
2
1
1
0
0

Representing Signed Integers

  • There are three possible schemes for representing signed numbers.
  • All agree on using the leftmost bit in the number to encode the sign

Sign-magnitude

  • The simplest way to represent negative numbers is called sign-magnitude.
  • It is based on the method we use with decimal numbers:
    • To represent a positive number in 8 bits, represent its magnitude as seven bits and prefix a 0.
    • To represent a negative number in 8 bits, represent its magnitude as seven bits and prefix a 1.
  • Example: +65  01000001
  • Example: - 65  11000001

Complement

1) r’s complement

complement of n = rn – n


2) (r-1)’s complement
complement of n = rn -1 – n

1’s Complement

In 1's complement, we proceed as follows:

    • To represent a negative number in 8 bits, represent it as an unsigned number using seven bits and prefix a 0, then invert all the bits
    • (which results in a left most bit of 1)

      example: +65  01000001

      1’s complement : - 65  10111110

2's complement

  • In 2’s complement, add 1 to the 1’s complement (in case of a negative number)
    • Example: +65  01000001
    • 1’s complement: - 65  10111110
    • 2’s complement : - 65  10111111

The left most bit (Most significant bit) is always reserved for the sign.
The biggest signed number to be stored in n bits is …..

Addition & Subtraction In Binary 2’complement


Examples
11000001 -63
01000000 64
------------ --
00000001 1
1
carry out of sign position discarded
00001000 8
111111111 -1
------------- --
00000111 7
-----------------------------------------
11111110 -2
11111110 -2
------------ --
11111100 -4
Addition & Subtraction In Binary 2’complement

01011010 90

01101100 + 108

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

11000110 198

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

00111001 57

01011010 + 90

--------

10010011 147


10000001 -127
111111101 - 3
------------- ------
011111110 -130
--------------------------------
10000001 -127
00000010 2
------------- ------
10000011 -125

Other Binary Codes

  • Binary Coded Decimal
  • 3 0011 6 0110 14 00010100 97 10010111

Text

  • ASCII (American Standard Code for Information Interchange): is the most widely used today.

Real Numbers

  • Real numbers 234.567
  • 11234.56

    0.00034567

  • Floating point: 2.34567 * 102
  • 1.123456 * 104

    3.4567 * 10-4

Real Numbers (2)

  • A real number is stored internally as a mantissa times a power of some radix
  • m * r e

  • r = 2 ( for binary)
  • m  mantissa

Single precision Format

  • IEEE has developed a floating point standard (Standard 754)
  • The standard provides two different formats for single and double-precision numbers.
  • We will consider the single precision representation as an example.

31
30
23
22
S
0
exp
mantissa

Single precision Format

  • s = sign of mantissa: 0 == +, 1 == -
  • exp = exponent as power of 2, stored in excess 127 form - i.e. value stored is 127 + true value.
    • ex: true exponent = 0; stored exponent = 127
    • ex: true exponent = 127; stored exponent = 254
    • ex: true exponent = -126; stored exponent = 1

31
30
23
22
S
0
exp
mantissa
fraction

Single precision Format

  • The leftmost bit is always 1, so it doesn’t need not be stored.
  • The 23 bits allocated are used to store the bits to the right of the binary point.
  • The missing leftmost bit “1” is inserted to the left of the binary point by the hardware when doing arithmetic.
  • (This is called hidden-bit normalization, and is why this field is labeled "fraction".)

IEEE Format

  • Example:
  • (-5.375) 10  (-101.011 ) 2 (-1.01011 x 22) 2

  • Sign bit =1 (negative)
  • exp = 2 + 127 = 129 = (10000001) 2
  • Significand= 1.01011
  • Fraction = 01011
  • IEEE format:
  • 1 10000001 01011000000000000000000
  • In Hex C0AC0000

Thank you


Download 0.78 Mb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page