Number Systems - PowerPoint PPT Presentation

About This Presentation
Title:

Number Systems

Description:

Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100, D=500, M=1000, L=50 – PowerPoint PPT presentation

Number of Views:2194
Avg rating:3.0/5.0
Slides: 90
Provided by: webCecsP
Learn more at: http://web.cecs.pdx.edu
Category:
Tags: number | systems

less

Transcript and Presenter's Notes

Title: Number Systems


1
Number Systems
  • Stone Age knots, some stone marks
  • Roman Empire more systematic notation I, II,
    III, IV, V, VI, VII.VIII, IX, X, C100, D500,
    M1000, L50
  • Concept of zero by
  • Maya- I century, Hindu-V century
  • Positional-value systems decimal, binary, octal,
    etc..

2
Positional-Value System
  • The value of a digit (digit from Latin word for
    finger) depends on its position

Positional values 2 1 0 -1
-2 -3 (weights) 10 10 10 10
10 10
5 6 7 . 9 1 4
MSD Decimal LSD point
We will write ( 5 6 7. 9 1 4)
10
3
BinaryBase-2 Number System
1 0 1 1 1 1 . 0 0 1
base point or radix
We write ( 1 0 1 1 1 1 . 0 0 1 )2
Digits are called bits
4
Binary Representation
  • The basis of all digital data is binary
    representation.
  • Binary - means two
  • 1, 0
  • True, False
  • Hot, Cold
  • On, Off
  • We must be able to handle more than just values
    for real world problems
  • 1, 0, 56
  • True, False, Maybe
  • Hot, Cold, LukeWarm, Cool
  • On, Off, Leaky

5
Number Systems
  • To talk about binary data, we must first talk
    about number systems
  • The decimal number system (base 10) you should be
    familiar with!
  • A digit in base 10 ranges from 0 to 9.
  • A digit in base 2 ranges from 0 to 1 (binary
    number system). A digit in base 2 is also called
    a bit.
  • A digit in base R can range from 0 to R-1
  • A digit in Base 16 can range from 0 to 16-1
    (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Use letters
    A-F to represent values 10 to 15. Base 16 is
    also called Hexadecimal or just Hex.

6
Positional Number Systems
  • The traditional number system is called a
    positional number system.
  • A number is represented as a string of digits.
  • Each digit position has a weight assoc. with it.
  • Numbers value a weighted sum of the digits

7
Positional Notation more examples
Value of number is determined by multiplying each
digit by a weight and then summing. The weight
of each digit is a POWER of the BASE and is
determined by position.
953.78 9 x 102 5 x 101 3 x 100 7 x 10-1
8 x 10-2 900 50 3 .7
.08 953.78
decimal
1011.11 1x23 0x22 1x21 1x20 1x2-1
1x2-2 8 0
2 1 0.5 0.25
11.75
binary
A2F 10x162 2x161 15x160
10 x 256 2 x 16 15 x 1
2560 32 15 2607
hex
8
Base 10, Base 2, Base 16
The textbook uses subscripts to represent
different bases (ie. A2F16 , 953.7810,
1011.112 )
We will use special symbols to represent the
different bases.The default base will be
decimal, no special symbol for base 10. The
will be used for base 16 ( A2F) The will
be used for base 2 (10101111)If ALL numbers
on a page are the same base (ie, all in base 16
or base 2 or whatever) then no symbols will be
used and a statement will be present that will
state the base (ie, all numbers on this page are
in base 16).
9
Common Powers
2-3 0.1252-2 0.252-1 0.520 121 222
423 824 1625 3226 6427 12828
25629 512210 1024211 2048212 4096
160 1 20161 16 24162 256 28163
4096 212
210 1024 1 K220 1048576 1 M (1
Megabits) 1024 K 210 x 210230 1073741824
1 G (1 Gigabits)
10
Octal and Hexadecimal (Hex) Numbers
  • Octal base 8
  • Hexadecimal base 16
  • Use A F to represent the values 10 through 16
    in each position.

11
Usefulness of Octal and Hex Numbers
  • Useful for representing multi-bit binary numbers
    because their radices are integer multiples of 2.

10 0101 1010 1111 . 1011 1112 2 5 A F . B E16
12
Comparison of binary, decimal, octal and
hexadecimal numbers
examples of octal and hex numbers
13
Decimal to Hex Conversions
Convert 53 to Hex
53/16 3, rem 5 3 /16 0 , rem 3
53 35 3 x 161 5 x 160
48 5 53
14
Hex (base 16) to Binary Conversion
Each Hex digit represents 4 bits. To convert a
Hex number to Binary, simply convert each Hex
digit to its four bit value.
Hex Digits to binary 0 0000 1
00012 00103 00114
01005 01016 01107
01118 1000
Hex Digits to binary (cont) 9 1001 A
1010 B 1011 C 1100 D
1101 E 1110 F 1111
15
Conversions Hex to Binary, Binary to Hex
A2F 1010 0010 1111 345
0011 0100 0101
Hex to Binary conversion
Binary to Hex is just the opposite, create
groups of 4 bits starting with least significant
bits. If last group does not have 4 bits, then
pad with zeros for unsigned numbers. 1010001
0101 0001 51
Binary to hex conversion
Padded with a zero
16
A Trick!
If faced with a large binary number that has to
be converted to decimal, we first convert the
binary number to HEX, then convert the HEX to
decimal. Less work!
110111110011 1101 1111 0011
D F 3
13 x 162 15 x 161
3x160 13 x
256 15 x 16 3 x 1
3328 240 3
3571
Of course, you can also use the binary, hex
conversion feature on your calculator. You can
use calculators on exam
17
Bah! I thought we were talking about Binary
DATA!!!
Yah, we were!
Key Question we must answer is ...

How many binary DIGITS does it take to represent
our data??
18
Binary Codes
One Binary Digit (one bit) can take on values 0,
1. We can represent TWO values (0 hot, 1
cold), (1 True, 0 False), (1 on,
0 off).Two Binary digits (two bits) can take
on values of 00, 01, 10, 11. We can
represent FOUR values (00 hot, 01
warm, 10 cool, 11 cold). Three Binary digits
(three bits) can take on values of 000, 001,
010, 011, 100, 101, 110, 111. We can represent 8
values000 Black, 001 Red, 010 Pink, 011
Yellow, 100 Brown, 101 Blue, 110 Green ,
111 White.
19
Binary Codes (cont.)
N bits (or N binary Digits) can represent 2N
different values. (for example, 4 bits can
represent 24 or 16 different values)N bits can
take on unsigned decimal values from 0 to
2N-1. Codes usually given in tabular form.
000001010011100101110111
blackredpinkyellowbrownbluegreenwhite
20
Code Conversions
21
( )2 ( )4 ( )8 ( )16
  • To convert a binary number to a system which is
    base-2z, group digits together by z and
    convert each group separately
  • 100111.1010 ---gt ( )16

Converting from binary base hex as an example of
base 2Z
2 7 . A
22
Conversion of Any Base to Decimal
Converting from ANY base to decimal is done by
multiplying each digit by its weight and summing.
Binary to Decimal
1011.11 1x23 0x22 1x21 1x20 1x2-1
1x2-2 8 0
2 1 0.5 0.25
11.75
Hex to Decimal
A2F 10x162 2x161 15x160
10 x 256 2 x 16 15 x 1
2560 32 15 2607
23
Conversion ( ) I ( )10
  • express number as a power series in I, and
    add all terms using decimal addition

Converting from base I to decimal
24
Decimal-to-Radix-r Conversions
  • Radix-r-to-decimal conversions are easy since we
    do arithmetic in decimal.
  • However, decimal-to-radix-r conversions using
    decimal arithmetic is harder.
  • To do the latter conversion, we convert the
    integer and fractional parts separately and add
    the results afterwards.

25
Convert ( ) 10 ( ) r
  • Integer part
  • Divide the number and all successive quotients
    by r
  • accumulate the remainders
  • Fractional part
  • Multiply the number and successive fractions by
    r
  • accumulate the integers

26
Conversion of Decimal Integer To ANY Base
Divide Number N by base R until quotient is 0.
Remainder at EACH step is a digit in base R, from
Least Significant digit to Most significant digit.
Convert 53 to binary
Least Significant Digit
53/2 26, rem 1 26/2 13, rem 0
13/2 6 , rem 1 6 /2 3, rem
0 3/2 1, rem 1 1/2 0,
rem 1 53 110101 1x25 1x24
0x23 1x22 0x21 1x20 32 16 0
4 0 1 53
Most Significant Digit
27
Decimal-to-Radix-r Conversions Integer Part
  • Successively divide number by r, taking remainder
    as result.
  • Example Convert 5710 to binary.

57 / 2 28 remainder 1 (LSB) /2 14
remainder 0 /2 7 remainder 0
/2 3 remainder 1
/2 1 remainder 1
/2 0
remainder 1 (MSB)
Answer 1110012
28
Decimal-to-Radix-r Conversions Fractional Part
  • Successively multiply number by r, taking integer
    part as result and chopping off integer part
    before next iteration.
  • May be unending!
  • Example convert .310 to binary.

.3 2 .6 integer part 0 .6 2 1.2 integer
part 1 .2 2 .4 integer part 0 .4 2 .8
integer part 0 .8 2 1.6 integer part 1 .6
2 1.2 integer part 1, etc.
Answer
29
More Conversion methods for common radices
30
Least Significant DigitMost Significant Digit
53 110101
Most Significant Digit (has weight of 25 or 32).
For base 2, also called Most Significant Bit
(MSB). Always LEFTMOST digit.
Least Significant Digit (has weight of 20 or 1).
For base 2, also called Least Significant Bit
(LSB). Always RIGHTMOST digit.
31
Binary Data in your life
The computer screen on your Win 98 PC can be
configured for different resolutions. One
resolution is 600 x 800 x 8, which means that you
have 600 dots vertically x 800 dots
horizontally, with each dot using 8 bits to take
on 256 different colors. (actually, a dot is
called a pixel). Need 8 bits to represent 256
colors ( 28 256). Total number of bits needed
to represent the screen is then 600 x 800
x 8 3,840,000 bits (or just under 4
Mbits)Your video card must have at least this
much memory on it. 1 Mbits 1024 x 1024 210
x 210 220 . 1 Kbits 1024 210.
32
Addition and Subtraction
  • Use same technique as decimal
  • Except that the addition and subtraction tables
    are different
  • Already seen addition table
  • Truth table for Sum and Cout function

33
Examples of decimal and corresponding binary
additions
34
Examples of decimal and corresponding binary
subtractions
35
Binary Addition and Subtraction Table
36
Subtraction table
borrow in
borrow out
Discuss this method in comparison with previous
method from the class to create a subtractor
37
Addition and Subtraction of Octal and Hexadecimal
Numbers
  • Not really too different
  • But the addition and subtraction tables must be
    developed.

38
The concept of 10s complement
39
digit complements in binary, octal, decimal and
hexadecimal
40
Representation of Negative Numbers
  • More accurately representation of signed numbers
  • Signed-magnitude representation
  • Radix-complement representation
  • 2s-complement representation
  • Diminished radix-complement representation
  • Ones complement representation
  • Excess representations

41
Comparison of decimal and 4-bit numbers.
Complements
Decimal numbers, their twos complements, ones
complements, signed magniture and excess 2m-1
binary codes
EXPLAIN
Existence of two zeros!
42
Signed-magnitude representation
  • Also called, sign-and-magnitude representation
  • A number consists of a magnitude and a symbol
    representing the sign
  • Usually 0 means positive, 1 negative
  • Sign bit
  • Usually the entire number is represented with 1
    sign bit to the left, followed by a number of
    magnitude bits

43
Machine arithmetic with signed-magnitude
representation
  • Takes several steps to add a pair of numbers
  • Examine signs of the addends
  • If same, add magnitudes and give the result the
    same sign as the operands
  • If different, must
  • Compare magnitude of the two operands
  • Subtract smaller number from larger
  • Give the result the sign of the larger operand
  • For this reason the signed-magnitude
    representation is not as popular as one might
    think because of its naturalness

44
Complement number systems
  • Negates a number by taking its complement instead
    of negating the sign
  • Exact meaning of taking its complement is defined
    in various ways will see
  • Not natural for humans, but better for machine
    arithmetic
  • Will describe 2 complement number systems
  • Radix complement very popular in real computers
  • Diminished radix-complement not very useful,
    may skip or not spend much time on it

45
Radix-complement number representation
  • Must first decide how many bits to represent the
    number say n.
  • Complement of a number rn number
  • Example 4-bit decimal
  • Original number 3524
  • 10s complement 10000-3524 6476
  • 0 and positive numbers 0000-4999
  • Negative numbers 5000-9999, where 9999 is minus
    1.

46
Twos-complement representation
  • Just radix-complement when radix 2
  • Used a lot in computers and other digital
    arithmetic circuits
  • 0 and positive numbers leftmost bit 0
  • Negative numbers leftmost bit 1
  • To find a numbers complement just flip all the
    bits and add 1
  • See graphical view Fig. 2.3, p. 40.

47
Twos-Comp Addition and Subtraction Rules
  • Starting from 1000 (-8) on up, each successive
    2s comp number all the way to 0111 (7) can be
    obtained by adding 1 to the previous one,
    ignoring any carries beyond the 4th bit position
  • Since addition is just an extension of ordinary
    counting, 2s comp numbers can be added by
    ordinary binary addition!
  • No different cases based on operands signs!
  • Overflow possible
  • Occurs if result is out of range
  • To detect happens if operands are the same sign
    but sum is a different sign of that of the
    operands

48
Modular Counting representation of Twos
Complements
49
Unsigned Numbers
Modular Counting representation of unsigned
numbers
50
Rules for addition and subtraction
51
  • DECIMAL CODES

52
Codes for Decimal Digits
There are even codes for representing decimal
digits. These codes use 4-bits for EACH decimal
digits it is NOT the same as converting from
decimal to binary.
BCD Code0 00001 00012
00103 00114 01005
01016 01107 01118
10009 1001
In BCD code, each decimal digit simply
represented by its binary equivalent. 96
1001 0110 96 (BCD code)Advantage
easy to convertDisadvantage takes more bits to
store a number 255 1111 1111 FF
(binary code) 255 0010 0101 0101 255
(BCD code)takes only 8 bits in binary, takes
12 bits in BCD.
53
Binary code for decimal numbers
  • Any encoding needs at least 4 bits/decimal digit
  • BCD (8421), a weighted code
  • Packed BCD
  • 2421 code
  • Self-complementing the code for the 9s comp of
    any digit may be obtained by complementing the
    individual bits of the digits code word
  • Excess 3
  • Not a weighted code, but is also
    self-complementing
  • Since code follows standard binary counting
    sequence, standard binary counters can easily be
    made to count in excess-3

54
Biquinary code
  • Uses more than 4 bits
  • First 2 bits indicate whether the number is in
    the range 0-4 or 5-0
  • One-hot
  • Last 5 bits indicate which of the five numbers in
    the selected range is represented
  • Also one-hot
  • Advantage error-detection property. If any 1
    bit in a code word is accidentally changed to the
    opposite value, the resulting code word doesnt
    represent a decimal digit at all flagged as
    error.

55
Codes for Characters
Also need to represent Characters as digital
data. The ASCII code (American Standard Code for
Information Interchange) is a 7-bit code for
Character data. Typically 8 bits are actually
used with the 8th bit being zero or used for
error detection (parity checking).8 bits 1
Byte. A 01000001 41
00100110 267 bits can only represent 27
different values (128). This enough to represent
the Latin alphabet (A-Z, a-z, 0-9, punctuation
marks, some symbols like ), but what about other
symbols or other languages?
56
UNICODE
UNICODE is a 16-bit code for representing
alphanumeric data. With 16 bits, can represent
216 or 65536 different symbols.16 bits 2 Bytes
per character. 0041-005A A-Z0061-4007A
a-z Some other alphabet/symbol ranges 3400-3d2d
Korean Hangul Symbols3040-318F
Hiranga, Katakana, Bopomofo, Hangul4E00-9FFF
Han (Chinese, Japenese, Korean)UNICODE used by
Web browsers, Java, most software these days.
57
033. 134 etc
Always two 1s
Decimal codes
58
  • GRAY CODES and mechanical encodings

59
A mechanical Encoding Disk
Two bits change in natural binary code
60
Gray Code for decimal Digits
Gray Code0 00001 00012
00113 00104 01105
11106 10107 10118
10019 1000
A Gray code changes by only 1 bit for adjacent
values. This is also called a thumbwheel code
because a thumbwheel for choosing a decimal digit
can only change to an adjacent value (4 to 5 to
6, etc) with each click of the thumbwheel. This
allows the binary output of the thumbwheel to
only change one bit at a time this can help
reduce circuit complexity and also reduce signal
noise.
61
Binary vs Gray Codes
You should be able to design binary to Gray code
converter in both directions
62
Always one bit changes only
A mechanical disk for Gray Code
63
7 bit ASCII code
You should be able to design a converter in both
directions from any code to any other code!
64
Example of sequence generator machine with
controlling counter machine
65
Controlling many devices with binary and one-hot
codes
66
  • Error Correcting Codes

67
The concept of a hypercube
68
(No Transcript)
69
(No Transcript)
70
Even-parity and odd-parity codes
71
Space of codes for 7 bits with code words and
non-code words
72
8-bit, distance 4 codes
73
Hamming Codes
Examples of Hamming Codes
74
7 bit Hamming codes
75
Extended Hamming Codes
76
Two dimensional codes
77
Error-correcting code for a RAID system
78
Serial data transmission
79
Well-known codes for serial data transmission
80
Multiplication and Division Intro
81
Binary multiplication
  • Grammar school method for decimal add a list of
    shifted multiplicands computed according to the
    digits of the multiplier
  • Same method can be used in binary
  • For two unsigned operands, the only possible
    values of the multiplier digits are 0 and 1
  • Thus its trivial to form the shifted
    multiplicands

82
Binary multiplication in binary on a machine
  • More convenient to add each shifted multiplicand
    as it is created to a partial product
  • Will do an example.
  • In general when we multiply an n-bit number by an
    m-bit number, the result requires at most nm
    bits to express
  • The shift-and-add algorithm requires m partial
    products and additions to obtain result, but the
    1st addition is trivial (adding to 0)

83
Long Division
84
Homework problem 1
  • Convert the following binary numbers to decimal
  • 1011011.0110
  • 00110.11001

85
Homework problem 2
Convert from decimal to binary
  • 0.5
  • 73.426
  • 290.9

86
Convert from Binary to Octal
Homework problem 3
  • 1 101 011 110 111
  • 11 011.101 1

87
Homework problem 4
  • Calculate 191141 (Lets first convert these to
    binary as an exercise.) Verify in decimal
  • 210 109, calculate first binary numbers.
    Verify.

88
Homework problem 5
  • Discuss how to convert hex, binary integers to
    Decimal
  • Discuss how to convert decimal integers to hex,
    binary
  • Discuss how to convert hex to binary, binary to
    Hex
  • Explain why N binary digits can represent 2N
    values, unsigned integers 0 to 2N-1.

89
sources
  • Bob Reese
  • Wakerly
  • Other from internet
Write a Comment
User Comments (0)
About PowerShow.com