Review Twos complement - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Review Twos complement

Description:

Negation means to find the corresponding negative number with the same ... If Negative: Fraction the negated number and negate binary number (invert and add 1) ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 11
Provided by: pagesSt
Category:

less

Transcript and Presenter's Notes

Title: Review Twos complement


1
Review Twos complement
2
Negate a Binary Number in 2C
  • Negation means to find the corresponding negative
    number with the same absolute value (in decimal
    the Negation of 10 is 10)
  • The method is the same whether you negate a
    positive to a negative or vice versa and doing it
    twice should give you the same result -(-a) a
  • Method
  • Invert the binary number (flip all bits)
  • Inverse (01001101) 10110010
  • Add to the result binary 1 (append 0s on the
    left)
  • 10110010 1101100100000000110110011

3
Convert Decimal to 2C
  • Decimal to Binary (word length k 8)
  • If positive Fraction number into a sum of powers
    of 2
  • bin(13)841232220 00001101
  • If Negative Fraction the negated number and
    negate binary number (invert and add 1)
  • bin(-13) Negate(bin(13)) Negate(00001101)
  • Invert(00001101)000000011111001
    000000001
  • 11110011

4
Convert 2C to Decimal
  • Binary to Decimal (word length k8)
  • If most significant bit (left most) is 0 the
    number is positive Sum the powers of 2
  • Dec(00101101)027 026125 024 123 122
    021 120
  • 112806413201618
    140210
  • 173
  • If most significant bit (left most) is 1 the
    number is negative, that means you can not just
    add the powers of 2
  • Find the decimal value of the negated binary
    number and negate it back in decimal (putting a
    in front)
  • Dec(10101101) - (Dec(Negate(10101101))
  • - (Dec(Invert(10101101
    )0000001))
  • - (Dec(01010010000000
    1))
  • - (Dec(01010011))
  • - now it is a positive number and we can sum
    the powers of 2!
  • -(641621) - 83

5
Operations on 2C
  • Addition bitwise including carry as in decimal
  • Negation Invert and add 1
  • Subtraction Addition of Negated operand
  • A B A ( B)
  • Multiplication by 2 Shift left
  • 00101101 2 01011010
  • Division by 2 Shift right
  • 00101101 2 00010110

6
Issues Binary Numbers
  • Signed Extension
  • Sometimes we are lazy and dont write out all
    bits. In 2C you can only add 0s to the left if
    the number is positive, otherwise you make a
    negative number positive
  • -3 1101 for k4
  • 11111101 for k8
  • For negative number you have to add 1sto the
    left!
  • Overflow
  • If the result of an addition/subtraction is
    bigger than the biggest or smaller than the
    smallest possible number of word length k
  • Can never happen if you add a positive and a
    negative number

7
Hexadecimal Numbers
  • Same principle as decimal and binary but with a
    base of 16
  • Number has a little x to the side xF5
  • Motivation Word size is either 32 or 64, that
    are very long binary numbers, in Hex you can save
    space
  • Conversion from Hex to binary is simple in blocks
    of 4(this works because 1624)
  • x5B2F 0101 1011 0010 1111
  • To decimal (if positive)
  • 5163 11162 2161 15160
  • 20480 2816 32 15
  • 23343

8
LOGICAL OPERATORS
  • AND is only 1 if all inputs are 1
  • OR is 1 if any of the inputs is 1
  • XOR is 1 if either input is 1
  • NOT is the inverse (flip the bit)

9
Logic on Words and Multiple Input
  • 00101101
  • AND 11101010
  • 00101000
  • 00101101
  • 10011000
  • AND 11101010
  • 00001000

00101101 OR 11101010 11101111
00101101 10011000 OR 11101010 11111111
10
Text Data ASCII Code
  • ASCII is a 7 bit encoding scheme for all keyboard
    symbols and some additional ones
  • Digits x30 to x39
  • Uppercase x41 to x5A
  • Lowercase x61 to x7A
  • Conversion Table
  • Question How can you mathematically convert a
    lowercase letter into uppercase?
Write a Comment
User Comments (0)
About PowerShow.com