Number Systems - PowerPoint PPT Presentation

1 / 57
About This Presentation
Title:

Number Systems

Description:

Digit do is the least significant digit (LSD). Digit dn-1 is the most ... 1G (giga or 'gibi') = (1K)*(1M) = 1,073,741,824. 6. Hexadecimal Number System. Base 16 ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 58
Provided by: reginal1
Learn more at: https://eng.fsu.edu
Category:
Tags: giga | number | systems

less

Transcript and Presenter's Notes

Title: Number Systems


1
Number Systems
  • Decimal, Binary, and Hexadecimal

2
Base-N Number System
  • Base N
  • N Digits 0, 1, 2, 3, 4, 5, , N-1
  • Example 1045N
  • Positional Number System
  • Digit do is the least significant digit (LSD).
  • Digit dn-1 is the most significant digit (MSD).

3
Decimal Number System
  • Base 10
  • Ten Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Example 104510
  • Positional Number System
  • Digit d0 is the least significant digit (LSD).
  • Digit dn-1 is the most significant digit (MSD).

4
Binary Number System
  • Base 2
  • Two Digits 0, 1
  • Example 10101102
  • Positional Number System
  • Binary Digits are called Bits
  • Bit bo is the least significant bit (LSB).
  • Bit bn-1 is the most significant bit (MSB).

5
Definitions
  • nybble 4 bits
  • byte 8 bits
  • (short) word 2 bytes 16 bits
  • (double) word 4 bytes 32 bits
  • (long) word 8 bytes 64 bits
  • 1K (kilo or kibi) 1,024
  • 1M (mega or mebi) (1K)(1K) 1,048,576
  • 1G (giga or gibi) (1K)(1M) 1,073,741,824

6
Hexadecimal Number System
  • Base 16
  • Sixteen Digits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  • Example EF5616
  • Positional Number System

0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
7
Collaborative Learning
Learning methodology in which students are not
only responsible for their own learning but for
the learning of other members of the group.
8
Think - Pair - Share (TPS) Quizzes
  • Think Pair Share
  • Think individually for one time units
  • Pair with partner for two time units
  • Share with group for one and half time units
  • Report results

9
Quiz 1-A (Practice)
  • Assemble in groups of 4
  • Question Convert the following binary number
    into its decimal equivalent
  • 110102

10
Quiz 1-A (Practice)
  • THINK
  • One Unit
  • (e.g. 30 Seconds)

11
Quiz 1-A (Practice)
  • PAIR
  • Two Units
  • (e.g. 60 Seconds)

12
Quiz 1-A (Practice)
  • SHARE
  • 1.5 units
  • (e.g. 45 Seconds)

13
Quiz 1-A (Practice)
  • Report
  • Write names of all group members and the
    consensus answer on one sheet of paper.
  • All sheets will be collected.
  • One will be picked at random to read to the
    class.
  • All papers will be graded!

14
Quiz 1-A Solution
  • Convert the following number into base 10 decimal

15
Quiz 1-B
  • Convert the following number into base 10
    decimal
  • 1010116

16
Collaborative Learning
  • Think for 30 seconds
  • Pair for 1 minute
  • Share for 45 seconds
  • Report

17
Quiz 1-B Solution
  • Convert the following number into base 10
    decimal
  • 1010116
  • 1164 0163 1162 0161 1160
  • 164 162 160
  • 65,536 256 1
  • 65,793

18
TPS Quiz 2
19
Binary Addition
  • Single Bit Addition Table

0 0 0
0 1 1
1 0 1
1 1 10 Note carry
20
Hex Addition
  • 4-bit Addition

4 4 8
4 8 C
8 7 F
F E 1D Note carry
21
Hex Digit Addition Table
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 0 1 2 3 4 5 6 7 8 9 A B C D E F
1 1 2 3 4 5 6 7 8 9 A B C D E F 10
2 2 3 4 5 6 7 8 9 A B C D E F 10 11
3 3 4 5 6 7 8 9 A B C D E F 10 11 12
4 4 5 6 7 8 9 A B C D E F 10 11 12 13
5 5 6 7 8 9 A B C D E F 10 11 12 13 14
6 6 7 8 9 A B C D E F 10 11 12 13 14 15
7 7 8 9 A B C D E F 10 11 12 13 14 15 16
8 8 9 A B C D E F 10 11 12 13 14 15 16 17
9 9 A B C D E F 10 11 12 13 14 15 16 17 18
A A B C D E F 10 11 12 13 14 15 16 17 18 19
B B C D E F 10 11 12 13 14 15 16 17 18 19 1A
C C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B
D D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C
E E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D
F F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E
22
TPS Quiz 3
23
Complements
  • 1s complement
  • To calculate the 1s complement of a binary
    number just flip each bit of the original
    binary number.
  • E.g. 0 ? 1 , 1 ? 0
  • 01010100100 ? 10101011011

24
Complements
  • 2s complement
  • To calculate the 2s complement just calculate
    the 1s complement, then add 1.
  • 01010100100 ? 10101011011 1
  • 10101011100
  • Handy Trick Leave all of the least significant
    0s and first 1 unchanged, and then flip the
    bits for all other digits.
  • Eg 01010100100 -gt 10101011100

25
Complements
  • Note the 2s complement of the 2s complement is
    just the original number N
  • EX let N 01010100100
  • 2s comp of N M 10101011100
  • 2s comp of M 01010100100 N

26
Twos Complement Representation for Signed Numbers
  • Lets introduce a notation for negative digits
  • For any digit d, define d -d.
  • Notice that in binary, where d ? 0,1, we have
  • Twos complement notation
  • To encode a negative number, we implicitly negate
    the leftmost (most significant) bit
  • E.g., 1000 (-1)000 -123 022 021
    020 -8

27
Negating in Twos Complement
  • Theorem To negatea twos complementnumber,
    just complement it and add 1.
  • Proof (for the case of 3-bit numbers XYZ)

28
Signed Binary Numbers
  • Two methods
  • First method sign-magnitude
  • Use one bit to represent the sign
  • 0 positive, 1 negative
  • Remaining bits are used to represent the
    magnitude
  • Range - (2n-1 1) to 2n-1 - 1
  • where nnumber of digits
  • Example Let n4 Range is 7 to 7 or
  • 1111 to 0111

29
Signed Binary Numbers
  • Second method Twos-complement
  • Use the 2s complement of N to represent
  • -N
  • Note MSB is 0 if positive and 1 if negative
  • Range - 2n-1 to 2n-1 -1
  • where nnumber of digits
  • Example Let n4 Range is 8 to 7
  • Or 1000 to 0111

30
Signed Numbers 4-bit example
  • Decimal 2s comp Sign-Mag
  • 7 0111 0111
  • 6 0110 0110
  • 5 0101 0101
  • 4 0100 0100
  • 3 0011 0011
  • 2 0010 0010
  • 1 0001 0001
  • 0 0000 0000

Pos 0
31
Signed Numbers-4 bit example
  • Decimal 2s comp Sign-Mag
  • -8 1000 N/A
  • -7 1001 1111
  • -6 1010 1110
  • -5 1011 1101
  • -4 1100 1100
  • -3 1101 1011
  • -2 1110 1010
  • -1 1111 1001
  • -0 0000 ( 0) 1000

32
Notes
  • Humans normally use sign-magnitude
    representation for signed numbers
  • Eg Positive numbers N or N
  • Negative numbers -N
  • Computers generally use twos-complement
    representation for signed numbers
  • First bit still indicates positive or negative.
  • If the number is negative, take 2s complement to
    determine its magnitude
  • Or, just add up the values of bits at their
    positions, remembering that the first bit is
    implicitly negative.

33
Example
  • Let N4 twos-complement
  • What is the decimal equivalent of
  • 01012
  • Since msb is 0, number is positive
  • 01012 41 510
  • What is the decimal equivalent of
  • 11012
  • Since MSB is one, number is negative
  • Must calculate its 2s complement
  • 11012 -(00101) - 00112 or -310

34
Very Important!!! Unless otherwise stated,
assume twos-complement numbers for all problems,
quizzes, HWs, etc.The first digit will not
necessarily be explicitly underlined.
35
TPS Quizzes 5-7
36
Arithmetic Subtraction
  • Borrow Method
  • This is the technique you learned in grade school
  • For binary numbers, we have

0 - 0 0
1 - 0 1
1 - 1 0
1
0 - 1 1 with a borrow
37
Binary Subtraction
  • Note
  • A (B) A (-B)
  • A (-B) A (-(-B)) A (B)
  • In other words, we can subtract B from A by
    adding B to A.
  • However, -B is just the 2s complement of B, so
    to perform subtraction, we
  • 1. Calculate the 2s complement of B
  • 2. Add A (-B)

38
Binary Subtraction - Example
  • Let n4, A01002 (410), and
  • B00102 (210)
  • Lets find AB, A-B and B-A

0 1 0 0 0 0 1 0
? (4)10
AB
? (2)10
0 11 0 6
39
Binary Subtraction - Example

0 1 0 0 - 0 0 1 0
? (4)10
A-B
? (2)10
0 1 0 0 1 1 1 0
? (4)10
A (-B)
? (-2)10
10 0 1 0 2
Throw this bit away since n4
40
Binary Subtraction - Example

0 0 1 0 - 0 1 0 0
? (2)10
B-A
? (4)10
0 0 1 0 1 1 0 0
? (2)10
B (-A)
? (-4)10
1 1 1 0 -2
1 1 1 02 - 0 0 1 02 -210
41
16s Complement method
  • The 16s complement of a 16 bit Hexadecimal
    number is just
  • 1000016 N16
  • Q What is the decimal equivalent of B2CE16 ?

42
16s Complement
  • Since sign bit is one, number is negative. Must
    calculate the 16s complement to find magnitude.
  • 1000016 B2CE16 ?????
  • We have
  • 10000
  • - B2CE

43
16s Complement
  • FFF10
  • - B2CE

2
3
D
4
44
16s Complement
  • So,
  • 1000016 B2CE16 4D3216
  • 44,096 13256 316 2
  • 19,76210
  • Thus, B2CE16 (in signed-magnitude)represents
    -19,76210.

45
Sign Extension
46
Sign Extension
  • Assume a signed binary system
  • Let A 0101 (4 bits) and B 010 (3 bits)
  • What is AB?
  • To add these two values we need A and B to be of
    the same bit width.
  • Do we truncate A to 3 bits or add an additional
    bit to B?

47
Sign Extension
  • A 0101 and B010
  • Cant truncate A!! Why?
  • A 0101 -gt 101
  • But 0101 ltgt 101 in a signed system
  • 0101 5
  • 101 -3

48
Sign Extension
  • Must sign extend B,
  • so B becomes 010 -gt 0010
  • Note Value of B remains the same
  • So 0101 (5)
  • 0010 (2)
  • --------
  • 0111 (7)

Sign bit is extended
49
Sign Extension
  • What about negative numbers?
  • Let A0101 and B100
  • Now B 100 ? 1100

Sign bit is extended
0101 (5) 1100 (-4) ------- 10001 (1)
Throw away
50
Why does sign extension work?
  • Note that (-1) 1 11 111 1111 1111
  • Thus, any number of leading 1s is equivalent, so
    long as the leftmost one of them is implicitly
    negative.
  • Proof 1111 -(1111) -(1000 - 111)
    -(1)
  • So, the combined value of any sequence of leading
    ones is always just -1 times the position value
    of the rightmost 1 in the sequence.
  • 1111000 (-1)2n

n
51
Number Conversions
52
Decimal to Binary Conversion
Method I Use repeated subtraction. Subtract
largest power of 2, then next largest, etc.
Powers of 2 1, 2, 4, 8, 16, 32, 64, 128, 256,
512, 1024, 2n Exponent 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10 , n
210
2n
29
28
20
27
21
22
23
26
24
25
53
Decimal to Binary Conversion
Suppose x 156410
Subtract 1024 1564-1024 (210) 540 ? n10
or 1 in the (210)s position
Subtract 512 540-512 (29) 28 ? n9
or 1 in the (29)s position
28256, 27128, 2664, 2532 gt 28, so we have 0
in all of these positions
Subtract 16 28-16 (24) 12 ?
n4 or 1 in (24)s position
Subtract 8 12 8 (23) 4 ? n3 or 1
in (23)s position
Subtract 4 4 4 (22) 0 ? n2
or 1 in (22)s position
Thus 156410 (1 1 0 0 0 0 1 1 1 0 0)2
54
Decimal to Binary Conversion
Method II Use repeated division by radix.
2 1564 782 R 0
2__24_ 12 R 0
2_____ 391 R 0
2_____ 6 R 0
?
2_____ 195 R 1
2_____ 3 R 0
2_____ 97 R 1
2_____ 1 R 1
2_____ 48 R 1
2_____ 0 R 1
2_____ 24 R 0
Collect remainders in reverse order
1 1 0 0 0 0 1 1 1 0 0
55
Binary to Hex Conversion
  1. Divide binary number into 4-bit groups

1 1 0 0 0 0 1 1 1 0 0
0
Pad with 0s If unsigned number
2. Substitute hex digit for each group
Pad with sign bit if signed number
61C16
56
Hexadecimal to Binary ConversionExample
  1. Convert each hex digit to equivalent binary

(1 E 9 C)16
(0001 1110 1001 1100)2
57
Decimal to Hex Conversion
Method II Use repeated division by radix.
16 1564 97 R 12 C
16_____ 6 R 1
?
16_____ 0 R 6
N 61C 16
Write a Comment
User Comments (0)
About PowerShow.com