Uploaded by mhamid111222333

Number Systems

advertisement
2/20/2013
Thought…
Lecture 1.1:
Number Systems

There are 10 kinds of people in this world…
Those who understand binary and those who don’t… 
Reference: Structured Computer Organization, Appendix A
Introduction

How do computers represent numbers?



Binary number system!
Binary uses digits 0 and 1 only to represent numbers
We will look at binary and a few other number
systems…
Radix Number Systems (1)
Radix Number Systems – radix means a base.
Example: radix 2  binary, radix 10  decimal, etc.
Finite Precision Numbers
Example:
In a set of positive integers represented by 3
decimal digits (000, 001, 002, …, 999), it may
be impossible to express numbers like
 Numbers larger than 999
 Negative numbers
 Fractions
 Irrational numbers
 Complex numbers
Radix Number Systems (2)
Other number systems – example decimal number 2001
in binary, octal, and hexadecimal:
The general form of a decimal number:
1
2/20/2013
Conversion from One Radix to
Another(1)
Decimal numbers and
their binary, octal, and
hexadecimal equivalents
4 X
Conversion from One Radix to
Another(2)
4 X
Conversion from One Radix to
Another(3)
More decimal numbers
and their binary, octal,
and hexadecimal
equivalents
Conversion from One Radix to
Another(4)
Examples of octal-to-binary and hexadecimal-to-binary
conversion (using grouping of bits):
Hexadecimal – group binary bits in 4s
Octal – group binary bits in 3s
Conversion from One Radix to
Another(5)
Conversion of the decimal
number 1492 to binary by
successive halving,
starting at the top and
working downward. For
example, 93 divided by 2
yields a quotient of 46
and a remainder of 1,
written on the line below
Conversion from One Radix to
Another(6)
Conversion of the binary number 101110110111 to
decimal by successive doubling, starting at the bottom.
Each line is formed by doubling the one below it and
adding the corresponding bit. For example, 749 is twice
374 plus the 1 bit on the same line as 749
2
2/20/2013
Representing Negative Numbers
Four ways:
• Signed magnitude
• Get absolute value of number and convert to binary
• Use first bit as sign bit: 0 if positive, 1 if negative
• Eg: Using 4 bits, 3 = 0011; -3 = 1011
• Problem - double representation of 0 (0000 and 1000)
• One’s complement
• Get absolute value of number and convert to binary
• If negative, invert bits (0 to 1 and 1 to 0)
• Eg: 3 = 0011; -3 = 1100
• Problem - double representation of 0 (0000 and 1111)
Negative Binary Numbers (1)
Negative 8-bit numbers in four ways:
Binary Arithmetic (1)
The addition table in binary:
Representing Negative Numbers
•
•
Two’s complement
• Invert bits as in one’s complement and add 1
• Eg: -3 = 1101
• No double representation of 0
Excess 2 m – 1
• For m bit numbers, store it as the number plus 2
4–1 = -3 + 8 = 5
• For m=4, -3  -3 + 2
= 0101
m–1
Negative Binary Numbers (2)
More negative 8-bit numbers in four ways:
Binary Arithmetic (2)
Addition in one’s complement and two’s complement:
3
2/20/2013
More on Number Systems


Like addition, you can also do subtraction,
multiplication and division with binary numbers – to
be practiced in tutorials in the coming weeks…
Characters can be represented in binary using ASCII
and other formats – to come later in the course!
4
Download