Todays Agenda - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Todays Agenda

Description:

If leading bit is one, take two's complement to get a positive number. ... Second Method: Subtract Powers of Two. Find magnitude of decimal number. ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 20
Provided by: discovery
Category:

less

Transcript and Presenter's Notes

Title: Todays Agenda


1
Todays Agenda
  • Representation of Binary Numbers
  • Unsigned, Signed Magnitude, 1s Compliment Done
    !!!
  • 2s Complement
  • Base Conversion
  • Binary to Decimal and Decimal to Binary Done !!!
  • Decimal to Octal and Octal to Decimal
  • Octal to Binary and Binary to Octal
  • Binary to Hexadecimal and Hexadecimal to Binary

2
Twos Complement Representation
  • If number is positive or zero
  • Normal binary representation
  • If number is negative
  • Start with positive number
  • Flip every bit (i.e., take the ones complement)
  • Then add one
  • Example

00101 (5) 01001 (9) 11010 (1s comp)
10110 (1s comp) 1 1 11011 (-5) 10
111 (-9)
3
Twos Complement Shortcut
  • To take the twos complement of a number
  • Copy bits from right to left until (and
    including) the first 1
  • Flip remaining bits to the left

011010000 011010000 100101111 (1s
comp) 1 100110000 100110000
(copy)
(flip)
4
Advantage of 2s complement
  • Twos complement representation developed to
    makecircuits easy for arithmetic.
  • For each positive number (X), assign value to its
    negative (-X),such that X (-X) 0 with
    normal addition, ignoring carry out

00101 (5) 01001 (9) 11011 (-5) 10111 (-9)
00000 (0) 00000 (0)
5
Example
  • 2(-3) ??
  • Express -3 in 2s complement form
  • 3 ? 00011
  • 1s Complement of 3 ? 11100
  • 2s Complement of 3 ? 11101
    i.e. -3
  • 2 ? 00010
  • -3 ? 11101
  • 11111
  • Look at MSB ? 1 So take 2s complement again
  • 00001

6
Twos Complement Signed Integers
  • MS bit is sign bit it has weight 2n-1.
  • Range of an n-bit number -2n-1 through 2n-1 1.
  • The most negative number (-2n-1) has no positive
    counterpart.

7
What is Base?
  • Decimal Number System
  • Base is 10
  • All numbers are represented by 0 to 9
  • Binary Number System
  • Base is 2
  • All numbers are represented by 0 and 1
  • Octal Number System
  • Base is 8
  • All numbers are represented by 0 to 7
  • Inference
  • Maximum digit value in any number system is Base
    -1

8
Converting Binary (2s C) to Decimal
  • If leading bit is one, take twos complement to
    get a positive number.
  • Add powers of 2 that have 1 in
    thecorresponding bit positions.
  • If original number was negative,add a minus
    sign.

Assuming 8-bit 2s complement numbers.
9
Example Binary to Decimal Conversion
  • X 01101000two
  • Step 1 Leading bit is 0 no need to take 2s
    complement
  • X 01101000
  • Step 2 Add powers of 2 that have 1 in the
    corresponding bit positions.
  • 262523 64328
  • X 104ten
  • Step 3 Not required (Number is positive)

10
More Examples
X 00100111two 25222120
32421 X 39ten
X 11100110two -X 00011010 242321
1682 26ten X -26ten
Assuming 8-bit 2s complement numbers.
11
Converting Decimal to Binary (2s C)
  • First Method Division
  • Find magnitude of decimal number. (Always ive)
  • Divide by two remainder is least significant
    bit.
  • Keep dividing by two until answer is zero,
    writing remainders from right to left.
  • Append a zero as the MS bit.
  • If original number was negative, take twos
    complement.

12
Example
  • X 104ten
  • 104/2 52 r 0 bit 0
  • 52/2 26 r 0 bit 1
  • 26/2 13 r 0 bit 2
  • 13/2 06 r 1 bit 3
  • 6/2 03 r 0 bit 4
  • 3/2 01 r 1 bit 5
  • 1/2 0 r 1 bit 6
  • X 01101000two

13
Converting Decimal to Binary (2s C)
  • Second Method Subtract Powers of Two
  • Find magnitude of decimal number.
  • Subtract largest power of two less than or equal
    to number.
  • Put a 1 in the corresponding bit position.
  • Keep subtracting until result is zero.
  • Append a zero as MS bit if original was
    negative, take twos complement.
  • Put a 0 in the other bit positions

14
Example
  • X 104ten 104 64 40 bit 7
  • 40 32 8 bit 6
  • 8 8 0 bit 4
  • X 01101000two

15
Decimal to Octal
  • Find magnitude of decimal number. (Always ive)
  • Divide by Eight remainder is least significant
    bit.
  • Keep dividing by Eight until answer is zero,
    writing remainders from right to left.
  • Example Convert 40410 to its octal equivalent.
  • Octal to Decimal
  • Sum the multiplication of each digit with its
    position value
  • Example Convert 6248 to its decimal
    equivalent.
  • 6 x 82 2 x 81 4 x 80 40410

16
Octal to Binary
  • First Method
  • First convert Octal number into its Decimal
    Equivalent and then From Decimal to Binary.
  • Second Method
  • Write 3-bit binary equivalent for each octal
    digit in the given number. Resultant number will
    be binary equivalent.
  • Example Binary equivalent of 6248
  • 110010100
  • Question How to convert a Binary number to its
    Octal equivalent?

17
Hexadecimal Notation
  • It is often convenient to write binary (base-2)
    numbers as hexadecimal (base-16) numbers instead.
  • Why?
  • Fewer digits -- four bits per hex digit
  • Less error prone -- easy to corrupt long string
    of 1s and 0s

18
Converting from Binary to Hexadecimal
  • Every four bits is a hex digit.
  • Start grouping from right-hand side
  • Example

011101010001111010011010111
7
D
4
F
8
A
3
This is not a new machine representation,just a
convenient way to write the number.
19
Exercise?
  • How we convert a Hexadecimal Number into Binary
    Number?
  • Try these
  • ADF6
  • DB69
  • CA36
  • 5678
  • DABC
Write a Comment
User Comments (0)
About PowerShow.com