Todays Material - PowerPoint PPT Presentation

1 / 44
About This Presentation
Title:

Todays Material

Description:

In any numerical system, the basis tells us how many different ... As a side note, Roman numerals is not a positional system. Consider the roman numeral: XXII ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 45
Provided by: muza6
Category:

less

Transcript and Presenter's Notes

Title: Todays Material


1
Todays Material
  • Number Systems
  • Decimal
  • Binary
  • Octal
  • Hexadecimal
  • Conversion between number systems
  • Arithmetic Operations
  • Representation of Signed Numbers
  • Sign-Magnitude
  • Ones Complement
  • Twos Complement

2
Decimal Numbers
  • Most commonly used numbering system
  • Based on the number 10
  • called the radix or basis of the system
  • In any numerical system, the basis tells us how
    many different symbols there are in the system
  • In decimal system, there are 10 symbols
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 each called a digit

3
Number Systems
  • In general, given any positive integer radix
    (base) N, there are N different individual
    symbols that can be used to write numbers in the
    system
  • The value of these symbols ranges from 0 to N-1
  • According to this definition
  • Decimal (radix 10) has 10 symbols
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Binary (radix 2) has 2 symbols
  • 0, 1
  • Octal (radix 8) has 8 symbols
  • 0, 1, 2, 3, 4, 5, 6, 7
  • Hexadecimal (radix 16) has 16 symbols
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A(10), B(11),
    C(12), D(13), E(14), F(15)

4
Notation
  • To indicate the basis on which a given number is
    written, we will use a subscript at the lower
    right side of the number
  • 10012
  • 0110112
  • 4568
  • 2278
  • 12356410
  • 129010
  • 1016
  • 2C116
  • FF16

5
Positional Systems
  • Binary, octal, decimal and hexadecimal systems
    are called positional systems
  • That is, the value represented by a symbol in the
    numerical representation of a number depends on
    its position in the number
  • E.g., digit 4 in decimal number 478 represents
    400 units whereas digit 4 in decimal number 842
    represents 40 units.
  • As a side note, Roman numerals is not a
    positional system
  • Consider the roman numeral XXII
  • position of X or I has no significance.
  • Decimal equivalent XXII 22

6
Calculating the Value of a Symbol
  • In positional systems, the value of any symbol in
    a number can be calculated as follows
  • Number the digits from right to left using
    superscripts. Begin with 0 as the superscript of
    the rightmost symbol, and increase superscripts
    by 1 as you move from left to right
  • Use each superscript to a power of the basis
  • Multiply the symbols own value in decimal by its
    corresponding power of the basis
  • Sum all products together to calculate the
    decimal equivalent of the entire number

7
Example I Decimal Number
  • Whats the value of each digit in 324510
  • (1) Number digits using superscripts
  • 33 22 41 50
  • (2-3) Use superscripts to form powers of the
    basis and multiply the digits own value, in
    decimal, by its corresponding power
  • The value of 3 in 3245 is equal to 3103 31000
    3000
  • The value of 2 in 3245 is equal to 2102 2100
    200
  • The value of 4 in 3245 is equal to 4101 410
    40
  • The value of 5 in 3245 is equal to 5100 51
    5
  • (4) Adding the decimal equivalent of each digit,
    we calculate the decimal equivalent of the number
  • 3000 200 40 5 3245

8
Example II Binary Number
  • Whats the value of each digit in 110012
  • (1) Number digits using superscripts
  • 14 13 02 01 10
  • (2-3) Use superscripts to form powers of the
    basis and multiply the digits own value, in
    decimal, by its corresponding power
  • The value of 1 in 11001 is equal to 124 116
    16
  • The value of 1 in 11001 is equal to 123 18
    8
  • The value of 0 in 11001 is equal to 022 04
    0
  • The value of 0 in 11001 is equal to 021 02
    0
  • The value of 1 in 11001 is equal to 120 11
    1
  • (4) Adding the decimal equivalent of each digit,
    we calculate the decimal equivalent of the number
  • 16 8 0 0 1 25

9
Example III Octal Number
  • Whats the value of each digit in 137028
  • (1) Number digits using superscripts
  • 14 33 72 01 20
  • (2-3) Use superscripts to form powers of the
    basis and multiply the digits own value, in
    decimal, by its corresponding power
  • The value of 1 in 13702 is equal to 184 14096
    4096
  • The value of 3 in 13702 is equal to 383 3512
    1536
  • The value of 7 in 13702 is equal to 782 764
    448
  • The value of 0 in 13702 is equal to 081 08
    0
  • The value of 2in 13702 is equal to 280 21
    2
  • (4) Adding the decimal equivalent of each digit,
    we calculate the decimal equivalent of the number
  • 4096 1536 448 0 2 6082

10
Example IV Hexadecimal Number
  • Whats the value of each digit in 3D8F16
  • (1) Number digits using superscripts
  • 33 D2 81 F0
  • (2-3) Use superscripts to form powers of the
    basis and multiply the digits own value, in
    decimal, by its corresponding power
  • The value of 3 in 3D8F is equal to 3163 34096
    12288
  • The value of D in 3D8F is equal to D162 13256
    3328
  • The value of 8 in 3D8F is equal to 8161 816
    128
  • The value of F in 3D8F is equal to F160 151
    15
  • (4) Adding the decimal equivalent of each digit,
    we calculate the decimal equivalent of the number
  • 12288 3328 128 15 15759

11
Conversion Between Binary, Octal, Hex
  • Here is the representation for the first 15
    decimal numbers in binary, octal, hex, decimal

Hex
Decimal
Binary
Octal
12
Hex-2-Binary
  • Given a hex number, we can find its binary
    equivalent by replacing each hex symbol by its
    binary equivalent
  • Whats the binary equivalent of hex number AF3C4?
  • A 10 1010
  • F 15 1111
  • 3 0011
  • C 12 1100
  • 4 0100
  • A F 3 C 4
  • 1010 1111 0011 1100 0100

13
Binary-2-Hex
  • To convert binary numbers to their hex
    equivalent, we reverse the process
  • Form 4-bit groups beginning from the rightmost
    bit of the binary number. If the last group at
    the leftmost position has less than 4 bits, add
    extra zeros to the left of the bits in this group
    to make it a 4-bit group
  • Replace each 4-bit group by its hex equivalent

14
Binary-2-Hex (cont)
  • Whats the hex equivalent of the following binary
    number 1101011010110
  • 11 1010 1101 0110
  • Add 0s to left of 11 to make it 0011
  • We have 0011 1010 1101 0110
  • 3 A D 6

15
Octal-2-Binary
  • Given an octal number, we can find its binary
    equivalent by replacing each octal symbol by its
    binary equivalent
  • Whats the binary equivalent of octal number
    23754?
  • 2 010
  • 3 011
  • 7 111
  • 5 101
  • 4 100
  • 2 3 7 5 4
  • 010 011 111 101 100

16
Binary-2-Octal
  • To convert binary numbers to their octal
    equivalent, we reverse the process
  • Form 3-bit groups beginning from the rightmost
    bit of the binary number. If the last group at
    the leftmost position has less than 3 bits, add
    extra zeros to the left of the bits in this group
    to make it a 3-bit group
  • Replace each 3-bit group by its octal equivalent

17
Binary-2-Octal Example
  • Whats the hex equivalent of the following binary
    number 1101011010110
  • 11 101 011 010 110
  • Add a 0 to the left of 11 to make it 011
  • We have 011 101 011 010 110
  • 3 5 3 2 6

18
Converting Decimal to Other Bases
  • Conversion of a given decimal number to another
    integer basis r (rgt0) is carried out by initially
    diving the number by r, and the successively
    dividing the quotients by until a zero quotient
    is obtained
  • Decimal equivalent is obtained by writing the
    remainders of the successive divisions in the
    opposite order to that in which they were
    obtained

19
Decimal-2-Binary Example
  • Whats the binary equivalent of decimal 46
  • Number Quotient when Remainder
  • Dividing by 2
  • 46 23 0
  • 23 11 1
  • 11 5 1
  • 5 2 1
  • 2 1 0
  • 1 0 1
  • Binary number is 101110
  • Verify this by converting it to decimal
  • 125 024 123 122 121 020
    32842 46

20
Decimal-2-Octal Example
  • Whats the octal equivalent of decimal 46
  • Number Quotient when Remainder
  • Dividing by 8
  • 46 5 6
  • 5 0 5
  • Octal number is 56
  • Verify this by converting it to decimal
  • 581 680 406 46

21
Decimal-2-Hex Example
  • Whats the hex equivalent of decimal 46
  • Number Quotient when Remainder
  • Dividing by 16
  • 46 2 14E
  • 2 0 2
  • Hex number is 2E
  • Verify this by converting it to decimal
  • 2161 E160 3214 46

22
Rules for Forming Numbers
  • Given a positional number system, how do we form
    consecutive numbers higher than that represented
    by the systems largest symbol?
  • Consider decimal number system
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Then how do we proceed?
  • After writing all single-digit numbers, we form
    all 2-digit combinations beginning with 1. Then
    we form all 2-digit combinations beginning with 2
    and so on until we reach 99.
  • After exhausting all 2-digit numbers, we start
    forming 3-digit combinations, then all 4-digit
    combinations and so on.

23
Rules for Forming Numbers (cont)
  • We follow a similar strategy in binary, octal and
    hex number systems
  • Binary Base 2
  • 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001,
    1010, 1011, ..
  • Octal Base 8
  • 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15,
    16, 17, 20, ..
  • Hex Base 16
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F,
    10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B,
    1C, 1D, 1E, 1F, 20, 21..

24
Arithmetic Operations (Addition)
  • Arithmetic operations in binary, octal and hex
    systems follow similar rules to the decimal
    system
  • In decimal, how do we add 342 and 485?

25 7 (no carry)
7
28 12-102 (carry 1)
2
134 8 (no carry)
8
  • Final result is 82710

25
Addition of Binary Numbers
  • Add the following binary numbers
  • 1101 (13)
  • 0111 (7)
  • 0 0 0
  • 0 1 1
  • 1 0 1
  • 1 1 0 with a carry of 1

110 (carry 1)
0
0
1010 (carry 1)
1111 (carry 1)
1
1100 (carry 1)
0
carry
1
  • Final result is 101002 2010

26
Addition of Octal Numbers
  • Add the following octal numbers
  • 3241
  • 276

167 (no carry)
7
3
4711-83 (carry 1)
1225 (no carry)
5
300 (no carry)
3
  • Final result is 35378

27
Addition of Hex Numbers
  • Add the following hex numbers
  • 1A23
  • 7C28

3811B (no carry)
B
4
224 (no carry)
AC22-166 (carry 1)
6
1179 (no carry)
9
  • Final result is 964B16

28
Arithmetic Operations (Subtraction)
  • In decimal, subtract 982 from 4015?

5-23B (no borrow)
3
11-83 (borrowed 10 from the left digit)
3
9-90 (borrowed 10 from the left digit, then
gave 1 to the right digit)
0
3-03 (gave 1 to the right digit)
3
  • Final result is 303310

29
Subtraction in other bases
  • Subtraction in other bases is very similar to
    decimal
  • When borrowing from the left digit, we borrow as
    big a number as the size of the radix
  • This means that
  • In binary, we borrow 2
  • In octal, we borrow 8
  • In hexadecimal, we borrow 16

30
Subtraction of Binary Numbers
  • Subtract 1112 (7) from 1000102 (34)

0
0
1
0
1
0
1
1
1
2-11 (borrowed 2 from the left digit)
1
1
2-11 (borrowed 2 from the left digit)
1-10 (borrowed 2 from the left digit,
gave 1 to the right digit)
0
1-01 (borrowed 2 from the left digit,
gave 1 to the right digit)
1
1
1-01 (borrowed 2 from the left digit,
gave 1 to the right digit)
  • Final result is 110112 2710

31
Subtraction of Octal Numbers
  • Subtract 2768 from 35378

7-61 (no borrow)
1
4
83-74 (borrowed 8 from the left digit)
4-22 (gave 1 to the right digit)
2
3-00 (no borrow)
3
  • Final result is 32418

32
Subtraction of Hex Numbers
  • Subtract 8C3 from 1F00A

1
A-37 (no borrow)
7
4
16-C(12)4 (borrowed 16 from the left digit)
F(15)-87 (borrowed 16 from the left digit,
gave 1 to the right digit)
7
E-0E (gave 1 to the right digit)
E
1-01
1
  • Final result is 1E74716

33
Hint on Arithmetic Operations
  • Arithmetic operations in binary is error prone
    for humans since we have to deal with lots of 0s
    and 1s
  • So when you are asked to work with binary
    numbers, first convert the binary number to
    hexadecimal, do the operation and convert back to
    binary representation

34
Representing Signed Numbers
  • Until now we have assumed that all numbers are
    unsigned, i.e., positive
  • How do we represent both positive and negative
    numbers with n bits?
  • General convention is to use one bit as the sign
    bit and the remaining n-1 bits as the magnitude
  • Leftmost bit represents the sign
  • 0 means a positive number, 1 means a negative
    number
  • Remaining n-1 bits represents the magnitude

35
Signed Number Conventions
  • There are 3 conventions used to represent signed
    numbers
  • Sign-and-Magnitude convention
  • Ones Complement convention
  • Twos Complement convention

36
Sign-and-Magnitude Convention
  • Given a basic unit of n bits, the leftmost bit
    represent the sign
  • The remaining n-1 bits represent the magnitude
  • The range of values that can be represented in
    this convention ranges from -2n-11, 2n-1-1
  • E.g. How do we represent -49 in 8 bits?
  • Bits 0-6 would represent the magnitude
  • Bit 7 would be the sign 1
  • Whats the binary value of 49? 0110001
  • So, 49 would be 00110001, -49 would be 10110001

37
Twos Complement Convention
  • Most popular convention
  • Positive numbers are represented similar to sign
    and magnitude
  • To represent a negative number do the following
  • (1) Express the absolute value of the number in
    binary
  • (2) Change all 0s to 1 and all 1s to 0
    (complement the number)
  • (3) Add one(1) to the binary number in step 2
  • The range of values that can be represented in
    this convention ranges from -2n-1, 2n-1-1

38
Twos Complement Convention (Ex)
  • How do we represent -49 in 8 bits?
  • Step1 49 00110001
  • Step2 Complement 11001110
  • Step 3 Add 1 11001111 CF
  • How do we represent -1?
  • Step1 1 00000001
  • Step2 Complement 11111110
  • Step3 Add 1 11111111 FF

39
Twos Complement Convention (Cont)
  • To find the positive equivalent of a negative
    number represented in 2s complement, simple
    apply steps 2 3
  • E.g. Given the negative number 11001111, whats
    the positive equivalent?
  • Step 2 Complement 00110000
  • Step 3 Add 1 00110001 49
  • E.g. Given 11111111, whats the positive
    equivalent?
  • Step2 Complement 00000000
  • Step 3 Add 1 00000001

40
Ones Complement Convention
  • Positive numbers are represented similar to sign
    and magnitude
  • To represent a negative number do the following
  • (1) Express the absolute value of the number in
    binary
  • (2) Change all 0s to 1 and all 1s to 0
    (complement the number)
  • The range of values that can be represented in
    this convention ranges from -2n-11, 2n-1-1

41
Ones Complement Convention (Ex)
  • How do we represent -49 in 8 bits?
  • Step1 49 00110001
  • Step2 Complement 11001110 CE
  • How do we represent -1?
  • Step1 1 00000001
  • Step2 Complement 11111110 FD

42
Representation of Some numbers in Different
Conventions
  • Notice that 0 has 2 representations in
    sign-magnitude and 1s complement conventions!
  • This complicates ALU design. So modern machines
    use 2s complement to represent signed numbers

43
Summary
  • Computers represent numbers in binary, which uses
    0s and 1s to represent numbers
  • Since dealing with binary numbers is difficult
    for humans, we can use octal or hexadecimal
    number systems to represent binary numbers
  • Signed numbers are represented in twos
    complement convention in modern architectures,
    which has a single representation for each number

44
Resources
  • There is a good interactive tutorial on
    http//courses.cs.vt.edu/csonline/NumberSystems/L
    essons/index.html
Write a Comment
User Comments (0)
About PowerShow.com