The University of Zambia
Department of Computing and
Informatics
CSC 2111- Computer Organisation and
Architecture
Lecturer: Mrs. Monde Kabemba
Email: [Link]@[Link]
Intended Learning Outcomes 2
•By the end of this unit, you should be able to:
•Explain the decimal, binary and hexadecimal number
systems
•Explain the binary representations of integers
•Perform 2’s complement arithmetic
•Explain the binary representation of floating-point
numbers
Chapter 10
Number Systems
Number systems
1. Decimal
2. Binary
3. Hexadecimal
The Decimal System
• A system based on decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
• All numbers are represented using the decimal digits.
• The decimal system is said to have a base, or radix, of 10.
• This means that each digit in the number is multiplied by 10 raised to
a power corresponding to that digit’s position:
The Decimal System
• Examples
Positional Number Systems
• Each number is represented by a string of digits in which each
digit position i has an associated weight ri, where r is the radix, or
base, of the number system.
• The general form of a number in such a system with radix r is:
• the value of any digit ai is an integer in the range
• The dot between a0 and a-1 is called the radix point.
• The number is defined to have the value:
The Binary System
• Two digits, 1 and 0 are used to represent numbers.
• Numbers in the binary system are represented to base 2.
• Each digit in a binary number has a value depending on its position:
• In general, for the binary representation of the value of Y is:
The Binary System
• Binary positional value box
8 4 2 1 0.5 0.25 0.125 0.0625
2^3 2^2 2^1 2^0 2^-1 2^-2 2^-3 2^-4
Converting Between Binary and Decimal
• Binary to Decimal
• Multiply each binary digit by the appropriate power of 2 and add the
results.
• Example 1: 0111.11
8 4 2 1 0.5 0.25 0.125 0.0625
0 1 1 1 1 1
• 7.75
Converting Between Binary and Decimal
•Binary to Decimal
•Example 2: 1111.0111
8 4 2 1 0.5 0.25 0.125 0.0625
1 1 1 1 0 1 1 1
•15.4375
•Class Exercise: 1111.1100
Converting Between Binary and Decimal
• Decimal to Binary (integer part)
• [1] By repeated divisions by 2.
• [2] By the subtraction method.
o 21-16 = 5
o 5-4 = 1
o 1-1 =0
o 16 + 4 + 1 = 21
32 16 8 4 2 1
1 0 1 0 1
Converting Between Binary and Decimal
• Decimal to Binary (fraction part)
• By repeated multiplication by 2.
• This process is not necessarily exact.
• A decimal fraction with a finite number
of digits may require a binary fraction
with an infinite number of digits. In such
cases, the conversion algorithm is usually
halted after a prespecified number of
steps, depending on the desired accuracy.
Converting Between Binary and Decimal
• Decimal to Binary (fraction part)
•By the subtraction method.
0.81 0.31 0.06 0.06 0.06 0.03 0.01 0.01
0.5 0.25 0.125 0.0625 0.03125 0.015625 0.007813 0.003906
1 1 0 0 1 1 1 1
Hexadecimal Notation
• Binary digits are grouped into sets of four bits, called a nibble.
• Each possible combination of four binary digits is given a symbol, as follows:
• Positional representation example
Hexadecimal Notation
• Using the positional value method, convert the following hexadecimal
numbers to decimal. [4 marks]
i. 0.59A
0.35010
ii. E2.81AC
226.50653
iii. F1.E
241.875
iv. [Link]
i. 204.796875
Decimal, Binary
and Hexadecimal
Chapter 11
Computer Arithmetic
Integer Representation
1. Unsigned
2. Signed
• Sign-Magnitude
• 1’s Complement
• 2’s Complement
Number Types
• Computer arithmetic is commonly performed on two very different
types of numbers: integer and floating point.
• Integer
• Whole number or fixed-point number with the radix
point fixed after the least-significant number.
• Integers include both positive and negative numbers including 0.
• Range: {….-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
9,…}
Number Types
•Computer arithmetic is commonly performed on two very
different types of numbers: integer and floating point.
•Floating point
•A positive or negative whole number with a decimal point.
•The position of the radix point varies
•Example: 5.5, 0.25, and -103.342
Integer Representation
• Computers use a fixed number of bits to represent an integer.
• The commonly-used bit-lengths for integers are 8-bit, 16-bit, 32-bit or
64-bit.
• Besides bit-lengths, there are two representation schemes for integers:
• Unsigned Integers: can represent zero and positive integers.
• Signed Integers: can represent zero, positive and negative integers.
Integer Representation
• Three representation
schemes are proposed for
signed integers:
1. Sign-Magnitude
representation
2. 1's Complement
representation
3. 2's Complement
representation
n-bit Unsigned Integers
• Unsigned integers can represent zero and positive integers, but not
negative integers.
• The value of an unsigned integer is interpreted as "the magnitude of its
underlying binary pattern".
• An n-bit unsigned integer can represent 2^n distinct integers
ranging from 0 to (2^n)-1
Signed Integers
•Signed integers can represent zero, positive integers, as well
as negative integers.
•Three representation schemes are available for signed integers:
•Sign-Magnitude representation
•1's Complement representation
•2's Complement representation
Signed Integers
•In all the three schemes, the most-significant bit (msb) is called
the sign bit.
•The sign bit is used to represent the sign of the integer: 0 for
positive integers and 1 for negative integers.
•The magnitude of the integer, however, is interpreted differently
in the different schemes.
n-bit Sign Integers in Sign-Magnitude Representation
• The most-significant bit (msb) is Unsigned Decimal Binary Sign-Magnitude
the sign bit, with value of 0 representing Decimal
positive integer and 1 representing 0 000 +0
negative integer. 1 001 +1
• The remaining n-1 bits represent the 2 010 +2
3 011 +3
magnitude of the integer.
4 100 -0
• The absolute value of the integer is
5 101 -1
interpreted as "the magnitude of the
6 110 -2
(n-1)bit binary pattern".
7 1 11 -3
n-bit Sign Integers in Sign-Magnitude Representation
Using Sign-Magnitude, what is the integer value:
Given n=8 and binary value 0111 1101.
+125
Given n=8 and binary value 1111 1101.
- 125
n-bit Sign Integers in Sign-Magnitude Representation
•Given
•n=8
Drawbacks to n-bit Sign Integers in Sign-Magnitude
Representation
• Two representations of 0, making it difficult to test for 0 (an operation performed
frequently on computers):
• Positive and negative integers need to be processed separately.
n-bit Sign Integers in 1's Complement Representation
• The most significant bit (msb) is the sign bit, with value of 0
representing positive integers and 1 representing negative integers.
• The remaining n-1 bits represent the magnitude of the integer.
n-1
MSB
n-bit Sign Integers in 1's Complement Representation
• For positive integers,
the absolute value of the
integer is equal to "the
magnitude of the (n-1)
bit binary pattern".
n-bit Sign Integers in 1's Complement Representation
• For negative integers, the
absolute value of the integer is
equal to "the magnitude of
the complement (inverse) of
the (n-1) bit binary pattern"
(hence called 1's complement).
n-bit Sign Integers in 1's Complement Representation
• Suppose that n=8
Drawbacks to n-bit Sign Integers in 1's Complement
Representation
• Two representations of 0, making it difficult to test for 0 (an
operation performed frequently on computers):
• Positive and negative integers need to be processed separately.
n-bit Sign Integers in 2's Complement Representation
• The most significant bit (msb) is the sign bit, with value of 0
representing positive integers and 1 representing negative integers.
• The remaining n-1 bits represent the magnitude of the integer, as
follows:
• for positive integers, the absolute value of the integer is equal to
"the magnitude of the (n-1)bit binary pattern".
n-bit Sign Integers in 2's Complement Representation
• For negative integers, the
absolute value of the integer is
equal to "the magnitude of
the complement of the (n-1) bit
binary pattern plus one" (hence
called 2's complement).
n-bit Sign Integers in 2's Complement Representation
n-bit Sign Integers in 2's Complement Representation
n-bit Sign Integers in 2's Complement Representation
• Computers use 2's complement in representing signed integers.
• This is because:
1. There is only one representation for the number zero in 2's
complement, instead of two representations in sign-magnitude and 1's
complement.
2. Positive and negative integers can be treated together in addition and
subtraction.
3. Subtraction can be carried out using the "addition logic“: A – B = A +
(-B)
Use of a Value Box for Conversion between Twos Complement Binary and
Decimal
• A value box is a useful illustration of the nature of twos complement
representation.
• The value on the far right in the box is 1 (20) and each succeeding position to
the left is double in value until the leftmost position, which is negated.
Use of a Value Box for Conversion between Twos Complement Binary and
Decimal
• The most negative twos complement number that can be represented is
-2n-1
• If any of the bits other than the sign bit is one, it adds a positive amount
to the number.
Use of a Value Box for Conversion between Twos Complement Binary and
Decimal
• A negative number must have a 1 at its leftmost position and a positive number must
have a 0 in that position.
• Thus, the largest positive number is a 0 followed by all 1s, which equals 2n-1 - 1.
Use of a Value Box for Conversion between Twos Complement Binary and
Decimal
• Covert decimal -120 to twos complement
Use of a Value Box for Conversion between Twos Complement Binary
and Decimal
•10000011 to decimal
Use of a Value Box for Conversion between Twos Complement
Binary and Decimal
1. For each of the following representation schemes, determine the decimal
value of binary number 1111 1010. [4 marks]
i. Unsigned
ii. Sign-Magnitude
iii. 1’s complement
iv. 2’s complement
• 250, -122, -5, -6
Range Extension
• Taking an n-bit integer and storing it in m bits, where m > n.
• The range of numbers that can be expressed is extended by increasing the
bit length.
• In sign-magnitude notation:
• simply move the sign bit to the new leftmost position and fill in with
zeros.
Range Extension
• The rule for twos complement integers is to move the sign bit to the new
leftmost position and fill in with copies of the sign bit.
• For positive numbers, fill in with zeros, and for negative numbers, fill in
with ones.
• This is called sign extension