Professional Documents
Culture Documents
TM103 Chapter 2
TM103 Chapter 2
Data Representation in
Computer Systems
3. Recognize the three ways in which signed binary integers may be expressed.
Example:
• 243.5110 = 2x102 + 4x101 + 3x100 + 5x10-1 + 1x10-2
• 10110.012 = 1x24 + 0x23 + 1x22 + 1x21 + 0x20 + 0x2-1 + 1x2-2= 22.2510
Pay attention to the fact that the first position (right-hand side) of the integer
part, will be multiplied by the base raised to power (0), and the first position
(left-hand side) of the fractional part will be multiplied by the base raised to
power (-1).
• You can notice that in the above example, where 243.5110, 3 was multiplied by 100,
November 27, 2023 TM103- Arab Open University 6
and 5 was multiplied by 10 .
-1
Lecture Overview
Introduction
Positional Numbering System
Converting from Decimal to any Base
Converting from any Base to Decimal
Converting between Bases
Converting Between Power-of-Two Bases
Signed integer representation
Floating-point representation
November 27, 2023 TM103- Arab Open University 7
Converting from Decimal to any Base
When dealing with numbers, you might face ones that contain
fractions. A number, hence may include an integer part and a
fraction part separated by a base point.
Base points separate the integer part of a number from its fractional
part. The “Base point” is called a “decimal point” in a decimal
system, a “binary point” in a binary system, and so on.
We will split our discussion about converting a number into two phases:
Because the remainder method works with positive powers of the base
for conversion of integers, it makes sense that we would use
multiplication to convert fractions, because they are expressed in
negative powers of the base.
0.34375
x2
0.68750 The integer part is 0
x2
1.37500 The integer part is 1
0.37500
x2
0.75000 The integer part is 0
x2
1.50000 The integer part is 1
Introduction
Positional Numbering System
Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
Converting from any Base to Decimal
Converting between Bases
Converting Between Power-of-Two Bases
Signed integer representation
Floating-point representation
November 27, 2023 TM103- Arab Open University 16
Converting from any Base to Decimal
Converting from any Base to Decimal
To convert from any base, say n, to decimal, all you need to do is
to multiply the digits, whether they were integers or fractions, by
the base n raised to the position of that digit.
Thus, given a number in base n, you can find the equivalent
value in decimal as follows:
1. Multiply each digit with the base n raised to the power of its
location.(Note that the LSB digit has a position of 0, and the digits after
the base point (fraction part) have negative powers starting from -1)
2. Add all the intermediate results to get the final equivalent
decimal value.
Introduction
Positional Numbering System
Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
Converting from any Base to Decimal
Converting between Bases
Converting Between Power-of-Two Bases
Signed integer representation
Floating-point representation
November 27, 2023 TM103- Arab Open University 19
Converting Between Bases
Converting Between Bases
Although there are direct ways to convert any number in any
base to any other base, it is faster and more accurate to convert
to base 10 and then to the desired base. One exception to this
rule exists when you are working between bases that are
powers of two, as you will see later in this section.
Working between bases that are powers of two, is much easier than
other bases.
In the next section, you will learn in details how to convert among
these
November bases.
27, 2023 TM103- Arab Open University 22
Lecture Overview
Introduction
Positional Numbering System
Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
Converting from any Base to Decimal
Converting Between Power-of-Two Bases
Signed integer representation
Floating-point representation
November 27, 2023 TM103- Arab Open University 23
Converting Between Power-of-Two Bases
Converting Between Power-of-Two Bases
The most famous power-of-two bases are: binary (base 2), octal (base 23
- base 8) and hexadecimal (base 24 - base 16).
2. Add zero(s) (on the left for the integer part, on the right for the
fraction part) to complete the last octet (if not complete)
2. Add zero(s) on the left to complete the last octet: 010 110 010 011
101
2 6 2 3 5
2. Add zero(s) (on the left for the integer part, on the right for the
fraction part) to complete the last hextet (if not complete)
2. Add zero(s) on the left to complete the last hextet: 0010 1100
1001 1101
2 C 9 D
Binary values are derived from Hex by representing each Hex digit by a group of
four binary bits.
Introduction
Positional Numbering System
Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
Converting from any Base to Decimal
Converting between Bases
Converting Between Power-of-Two Bases
Signed integer representation
Floating-point representation
November 27, 2023 TM103- Arab Open University 30
Signed integer representation
The conversions we have so far presented have involved only unsigned
numbers.
To represent signed integers, computer systems allocate the high-order bit to
indicate the sign of a number.
The high-order bit is the leftmost bit. It is also called the most significant bit.
0 is used to indicate a positive number; 1 indicates a negative number.
The remaining bits contain the value of the number (but this can be
interpreted different ways).
0 1110010 (114)
1 (discarded) 1 ⇐ carries
0 1000001 (65)
0 +1100001 ( 97)
______________
0 0100010 (34) which is erroneous!
0112 ⇐ borrows
0 1100011 (99)
1 - 1001111 (-79)
_____________
0 0010100 (20)
Answer: Here, you can notice that the MSB is 1. Then, you have to complement all
the bits of the C1 number first, and then find the equivalent value in decimal.
Finally, remember to add the negative sign.
11110110C1
Complement: 000010012
Convert :9
Include (-) : -9
November 27, 2023 TM103- Arab Open University 41
Signed integer representation
Adding numbers in C1:
In one’s complement, the subtraction is converted into addition.
For example: 2310 – 910 = 2310 + (-910).
In C1, we add all digits including the sign bits. If we have a carry out 1 from the
eighth bits addition, then this 1 will be added to the sum.
Example 1: Add 2310 to -910 using 8-bit binary one’s complement arithmetic .
In a previous example, we have calculated the C1 values of 23 and -9.
Summary:
Although the “end carry around” adds some complexity, one’s complement is
simpler to implement than signed magnitude.
Nevertheless, it still has the disadvantage of having two different representations
for zero: positive zero and negative zero (00000000 & 11111111).
Two’s complement solves this problem.
November 27, 2023 TM103- Arab Open University 43
Signed integer representation
Two’s Complement Representation
In One’s complement, we still have two representations for zero: 00000000
and 11111111. Computer engineers long ago stopped using one’s
complement.
A more efficient representation for binary numbers is: two’s complement.
Carries: 1 1 1 1 0 1 1 1
0 0 0 1 0 1 1 1 2310
+ 1 1 1 1 0 1 1 1 + (-910)
0 0 0 0 1 1 1 0 +1410
As you can see, the carry-in is 1, while the carry-out is 0. Since the two
carries are different, we have an overflow and an erroneous result
(- 106, where the result should be 152)
Introduction
Positional Numbering System
Converting from Decimal to any Base
Converting from any Base to Decimal
Converting between Bases
Converting Between Power-of-Two Bases
Signed integer representation
Floating-point representation
We know that 32 is 25. The scientific notation 32 = 1.0 x 2 5 = 0.1 x 26. (In a moment, we will
explain why we prefer the second notation versus the first.)
Using this information, we put 0 in the sign field, 00110 (= 610) in the exponent field
and 10000000 in the significand as shown.
3210 will be:
0 00101 10011000
We could fix the problem by adding a sign bit to the exponent, but
it turns out that it is more efficient to use a biased exponent,
because we can use simpler circuits designed specifically for
unsigned numbers when comparing the values of two floating-
point
Novembernumbers.
27, 2023 TM103- Arab Open University 58
Floating-point representation
To solve such problems we use an excess-16 bias:
All negative and positive exponents are added by 16
We say that the real exponent is replaced by a biased
exponent
All exponents are converted to positive biased exponents
1 0 1 1 0 0 1 0 0 0 0 0 0 0
Floating-point Arithmetic
To add/subtract two numbers in floating point form, both numbers should
have the same exponent.
If exponents are different, you should change one of the numbers so that
both of them are expressed in the same power of the base. Then, you add
the binary numbers, and represent the result in a normalized floating-point
form.
Example: Add the following binary numbers as represented in a normalized
14-bit format with an excess-16 bias.
Looking at the exponents fields, you can notice that they are different:
The first representation has an exponent value 1810 → 210 (you deduct the 16 that is already
added, as you are working with excess-16 bias)
The second representation has an exponent value 1610 → 010 (you also deduct the 16)
November 27, 2023 TM103- Arab Open University 63
Floating-point representation
Let us explain the representation of each number.
The first number is 0.11001000x22 (recall that the fraction is derived from the
significand field)
Now, change one of the numbers so that both of them will have the same exponent.
We will change the first number, so that its exponent will be 0 instead of 2:
0.11001000x22 = 11.001000x20 ( you simply shift the binary point two places to the
left)