Numbering Systems and Conversions Guide
Numbering Systems and Conversions Guide
(2.1): Introduction
(2.2): Positional Numbering Systems
[Link]
Chapter 2 Objectives
● Understand the fundamental concepts of floating-
point representation.
[Link]
Chapter 2 Objectives
3
2.1 Introduction
• A bit is the most basic unit of information in a computer.
– It is a state of “on” or “off” in a digital circuit.
– Sometimes these states are “high” or “low” voltage instead of “on” or “off..”
• A byte is a group of eight bits.
– A byte is the smallest possible addressable unit of computer storage.
– The term, “addressable,” means that a particular byte can be retrieved
according to its location in memory.
4
2.1 Introduction
• A word is a continuous group of bytes.
• Words can be any number of bits or bytes.
• Word sizes of 16, 32, or 64 bits are most common.
• In a word-addressable system, a word is the smallest addressable unit of
storage.
• A group of four bits is called a nibble.
• Bytes, therefore, consist of two nibbles: a “high-order nibble,” and a “low-
order” nibble.
5
Different Numbering Systems
• Decimal (Arabic): (0,1,2,3,4,5,6,7,8,9):
• Example: (452968) 10
• Binary: (0,1):
• Example: (1001110001011)2
• Octal: (0,1,2,3,4,5,6,7):
• Example (4073) 8
• Hexadecimal(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
• Example: (2BF3) and so one
16
6
2.2 Positional Numbering Systems
• Bytes store numbers using the position of each bit to represent a
power of 2.
• The binary system is also called the base-2 system.
• Our decimal system is the base-10 system. It uses powers of 10
for each position in a number.
• Any integer quantity can be represented exactly using any base (or
radix).
7
2.2 Positional Numbering Systems
• 9 10 2 + 4 10 1 + 7 10 0
• The decimal number 5836.47 in powers of 10 is:
5 10 3 + 8 10 2 + 3 10 1 + 6 10 0
+ 4 10 -1 + 7 10 -2
8
Base in Numbering systems [2]
The binary numbering system is called binary because it uses base 2. The
values of the positions are calculated by taking 2 to some power.
Base 2 for binary numbers :
It uses 2 digits. The digits 0 and 1.
9
Binary numbers
Digits = {0, 1}
(11010.11)2 = 1 x 24 + 1 x 23 + 0 x 22 +
1 x 21 + 0 x 20 + 1 x 2-1 + 1 x 2-2
– 1 K (kilo) = 210 = 1,024
–1M (mega) = 220 = 1,048,576
–1G (giga) = 230 = 1,073,741,824
10
2.3 Converting between bases
Radix
point
Integer part and Fractional part are
converted differently
11
Converting the Integer Part
• keep dividing by 2 until the quotient is 0. Collect
the remainders in reverse order.
• Example: (162) . 10
162 / 2 = 81 rem 0
81 / 2 = 40 rem 1
40 / 2 = 20 rem 0
20 / 2 = 10 rem 0
10 / 2 =5 rem 0
5/2 =2 rem 1
2/2 =1 rem 0
1/2 =0 rem 1
14
Why does this work? [2]
0.375 x 10 = 3.750
0.750 x 10 = 7.500
0.500 x 10 = 5.000
• Each multiplication “strips off” the leftmost digit
(the integer part). The fraction represents the
remaining digits.
15
Converting binary to decimal
• To convert binary, or base 2, numbers to decimal we first
obtain the polynomial representation of the number, then sum
the products.
• Example: (1101.01)2
1 1 0 1 . 0 1 Binary digits, or bits
23 22 21 20 2-1 2-2 Weights (in base 10)
16
Octal number system
–Digits = {0, 1, 2, 3, 4, 5, 6, 7}
Positional = Polynomial
(127.4)8= 1 x 82 + 2 x 81 + 7 x 80 + 4 x 8-1
17
Converting Decimal to Octal
Integer part: keep dividing by 8 until the
quotient is 0. Collect the remainders in reverse
order.
19
Converting Binary to Octal
•To convert from binary to octal, make groups of 3 bits,
starting from the binary point. Add 0s to the beginin of the
number if needed. Then convert each group of bits to its
corresponding octal digit.
Example
20
Converting Octal to Binary
(261.35) 8 = (2 6 1 . 3 5 )8
= (010 110 001 . 011 101)2
21
Hexadecimal numbers
-Digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
Positional Polynomial(Radix-Power of 2)
- (B65F)16 = 11 x 163 + 6 x 162 + 5 x 161 + 15 x 160
22
Converting Decimal to Hexadecimal
24
Converting Hexadecimal to Binary
• To convert from hexadecimal to binary, replace
each hex digit with its equivalent 4-bit binary
sequence.
• Example
261.3516 = (2 6 1 . 3 5 )16
= (0010 0110 0001 . 0011 0101)2
25
Converting Binary to Hexadecimal
•To convert from binary to hex, make groups of 4 bits,
starting from the binary point. Add 0s to the ends of
the number if needed. Then convert each group of bits
to its corresponding hex digit.
•Example
26
2.3 Converting Between Bases
• Fractional values can be approximated in all base systems.
• Unlike integer values, fractions do not necessarily have exact
representations under all radices.
• The quantity ½ is exactly representable in the binary and decimal
systems, but is not in the ternary (base 3) numbering system.
27
2.3 Converting Between Bases
• Converting 190 to base 3...
• First we take the number that we wish to
convert and divide it by the radix in
which we want to express our result.
• In this case, 3 divides 190 63 times,
with a remainder of 1.
• Record the quotient and the remainder.
28
2.3 Converting Between Bases
• Converting 190 to base 3...
• 63 is evenly divisible by 3.
• Our remainder is zero, and the
quotient is 21.
29
2.3 Converting Between Bases
30
2.3 Converting Between Bases
• Using the multiplication method
to convert the decimal 0.8125 to
binary, we multiply by the radix
2.
• The first product carries into the
units place.
31
2.3 Converting Between Bases
• Converting 0.8125 to binary . . .
• Ignoring the value in the units place
at each step, continue multiplying
each fractional part by the radix.
32
2.3 Converting Between Bases
• Converting 0.8125 to binary . . .
• You are finished when the
product is zero, or until you
have reached the desired
number of binary places.
• Our result, reading from top
to bottom is:
• 0.812510 = 0.11012
• This method also works with
any base. Just use the target
radix as the multiplier.
33
2.3 Converting Between Bases
34
Exercises
• Chap. 2 ex:13
-Convert: (AC12)16 to binary.
• Solution: (1010110000010010)2 ?
• Perform the following conversions:
-Convert (ABBA)16 = (?)2
• (1101 1110 1010 1111)2 = (?)16
-(ABCD)16 = (?)8
35
Exercises
• Perform the following conversions:
• 45810 = (?)3
• 67710 = (?)5
• 25.7510 = (?)2
• 5006 = (?)4
36
Solution
• Perform the following conversions:
• 45810 = (121222)3
• 67710 = (10202)5
• 25.7510 = (11001.11)2
• 5006 = (2310)4 => (180) 10
37
Exercises
• Ex 7 a,b P118
a)11010.11001 b) 11000010.00001
• Ex 10 a,d
a) 23.8125 d) 194.875
38
(PART-2-(2.4): Signed Integer Representation)
39
2.4 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
depending on the representation)
40
2.4 Signed Integer Representation
•There are three ways in which signed binary integers may be
expressed:
–Signed magnitude
–One’s complement
–Two’s complement
•In an 8-bit word, signed magnitude representation places the absolute
value of the number in the 7 bits to the right of the sign bit.
41
2.4 Signed Integer Representation
•For example, in 8-bit signed magnitude
representation:
– +3 is: 0 0000011
– - 3 is: 1 0000011
•Computers perform arithmetic operations on
signed magnitude numbers in much the same way
as humans carry out pencil and paper arithmetic.
–Humans often ignore the signs of the operands
while performing a calculation, applying the
appropriate sign after the calculation is complete.
42
2.4 Signed Integer Representation
•Binary addition is as easy as it gets. You need to know only four rules:
• 0+0= 0 0+1= 1
• 1 + 0 = 1 1 + 1 = 0, carry 1
• 1 + 1 + 1 = 1, carry 1
•The simplicity of this system makes it possible for digital circuits to
carry out arithmetic operations.
•We will describe these circuits in Chapter 3.
Let’s see how the addition rules work with signed
magnitude numbers . . .
43
Examples
•Apply the following addition using 8-bit binary:
10110100
00101101 +
------------------------
11100001
44
2.4 Signed Integer Representation
•Example:
•Using signed magnitude binary arithmetic, find the sum of 75 and
46.
•First, convert 75 and 46 to binary, and arrange as a sum, but separate
the (positive) sign bits from the magnitude bits.
45
2.4 Signed Integer Representation
•Example:
•Using signed magnitude binary arithmetic, find the sum of 75 and
46.
•Just as in decimal arithmetic, we find the sum starting with the
rightmost bit and work left.
46
2.4 Signed Integer Representation
•Example:
•Using signed magnitude binary arithmetic, find the sum of 75 and
46.
•In the second bit, we have a carry, so we note it above the third bit.
47
2.4 Signed Integer Representation
•Example:
•Using signed magnitude binary arithmetic, find the sum of 75 and
46.
•The third and fourth bits also give us carries.
48
2.4 Signed Integer Representation
•Example:
•Using signed magnitude binary arithmetic, find the sum of 75 and
46.
•Once we have worked our way through all eight bits, we are done.
49
2.4 Signed Integer Representation
•Example:
–Using signed
magnitude binary
arithmetic, find the
sum of 107 and 46.
•We see that the carry
from the seventh bit
overflows and is
discarded, giving us the
erroneous result: 107 +
46 = 25.
50
2.4 Signed Integer Representation
•The signs in signed
magnitude
representation work just
like the signs in pencil
and paper arithmetic.
•Example: Using signed
magnitude binary
arithmetic, find the
sum of - 46 and - 25.
• Because the signs are the same, all we do is
add the numbers and supply the negative
sign when we are done. 51
2.4 Signed Integer Representation
•Mixed sign addition
(or subtraction) is
done the same way.
•Example: Using
signed magnitude
binary arithmetic,
find the sum of 46
and - 25.
53
Exercises
•Using signed magnitude representation:
–Add (-19) to (+13)
–Subtract (-24) from (-43)
–Add (-8) to (-12)
–Add (-8) to (+12)
–Add (+8) to (-12)
–Subtract (-8) from (-12)
–Add (+8) to (-5)
–Add (-16) to (+15)
54
2.4 Signed Integer Representation
55
2.4 Signed Integer Representation
•In complement systems, negative values are represented by some
difference between a number and its base.
•The diminished radix complement of a non-zero number N in base r
with d digits is (rd – 1) – N
•In the binary system, this gives us one’s complement. It amounts to
little more than flipping the bits of a binary number.
56
2.4 Signed Integer Representation
•For example, using 8-bit one’s complement
representation:
– + 3 is: 00000011
– - 3 is: 11111100
•In one’s complement representation, as with
signed magnitude, negative values are indicated
by a 1 in the high order bit.
•Complement systems are useful because they
eliminate the need for subtraction. The difference
of two values is found by adding the minuend to
the complement of the subtrahend.
57
Additional Examples
Example 1
•What decimal value does the 8-bit binary number 11001101 have
if:
a) it is interpreted as an unsigned number?
b) it is on a computer using signed-magnitude representation?
c) it is on a computer using one’s complement representation?
d) it is on a computer using two’s complement
representation?
Solution:
a) Unsigned: we use the number as is because there is no sign:
11001101 = 205
b) Signed-High order bit becomes sign bit: 1 1001101 = - 77
c) One’s complement: transfer one to zero and zero to one:
00110010 = -50
d) Tow’s complement: add 1 to one’s complement, becomes:
00110011=-51 58
Example 2
•What decimal value does the 8-bit binary number 01001101 have
if:
a) it is interpreted as an unsigned number?
b) it is on a computer using signed-magnitude representation?
c) it is on a computer using one’s complement
representation?
d) it is on a computer using two’s complement
representation?
Solution:
a) Unsigned: we use the number as is because there is no sign:
01001101 = 77
b) Signed-High order bit becomes sign bit: 0 1001101 = + 77
c) One’s complement: transfer one to zero and zero to one:
01001101 = 77
d) Tow’s complement: add 1 to one’s complement, becomes:
01001101 = 77
59
Example 3
Q1: What is the representation of (-33)10 in binary using One’s
complement & two’s complement is:
One’s complement:
33 in binary is: 00100001
Now -33: because it is minus, replace one to zero and zero to
one. The result will be:
11011110
Two’s complement:
33 in binary is: 00100001
Now -33: because it is minus, replace one to zero and zero to
one. The result will be:
11011110
Add one:
11011111
Q2: What is the representation of (33)10 in binary using One’s
complement is:
The result will be: 33 in binary is: 00100001 because the
number is positive.
60
2.4 Signed Integer Representation
•With one’s complement
addition, the carry bit is
“carried around” and added
to the sum.
•Example: Using one’s
complement binary We note that
19 in binary is
arithmetic, find the sum of 00010011,
48 and - 19 so -19 in one’s
complement
is:
11101100
.
61
2.4 Signed Integer Representation
•Although the “end carry around” adds some
complexity, one’s complement is simpler to
implement than signed magnitude.
•But it still has the disadvantage of having two
different representations for zero: positive zero and
negative zero.
•Two’s complement solves this problem.
•Two’s complement is the radix complement of the
binary numbering system; the radix complement of
a non-zero number N in base r with d digits is rd – N.
62
2.4 Signed Integer Representation
63
2.4 Signed Integer Representation
•With two’s complement
arithmetic, all we do is add
our two binary numbers.
Just discard any carries
emitting from the high
order bit.
– Example: Using
two’s complement
We note that 19 in binary is:
binary arithmetic, 00010011,
64
Exercises
•Represent the following decimal numbers in binary using one’s
complement, and two’s complement:
•(77)
•(-42)
•(-20)
65
Exercises
•Using 2’s complement representation:
•Add 23 to -9
•Add -23 to 9
66
2.4 Signed Integer Representation
•We can do binary multiplication and division by 2 very easily using an
arithmetic shift operation
•A left arithmetic shift inserts a 0 in for the rightmost bit and shifts
everything else left one bit; in effect, it multiplies by 2
•A right arithmetic shift shifts everything one bit to the right, but
copies the sign bit; it divides by 2
•Let’s look at some examples.
67
2.4 Signed Integer Representation
•Example:
•Multiply the value 11 (expressed using 8-bit signed
two’s complement representation) by 2.
•We start with the binary value for 11:
• 00001011 (+11)
•We shift left one place, resulting in:
• 00010110 (+22)
•The sign bit has not changed, so the value is valid.
To multiply 11 by 4, we simply perform a left shift twice.
68
2.4 Signed Integer Representation
•Example:
•Divide the value 12 (expressed using 8-bit signed two’s complement
representation) by 2.
•We start with the binary value for 12:
• 00001100 (+12)
•We shift right one place, resulting in:
• 00000110 (+6)
•(Remember, we carry the sign bit to the left as we shift.)
To divide 12 by 4, we right shift twice.
69
(PART-3) 2.5 Floating-Point Representation
70
2.5 Floating-Point Representation
• To provide for negative exponents, we will use a
biased exponent.
• A bias is a number that is approximately midway in
the range of values expressible by the exponent. We
subtract the bias from the value in the exponent to
determine its true value.
– In our case, we have a 5-bit exponent. We will use 16 for
our bias. This is called excess-16 representation.
• In our model, exponent values less than 16 are
negative, representing fractional numbers.
71
2.5 Floating-Point Representation
• The signed magnitude, one’s complement, and two’s complement
representation that we have just presented deal with signed integer
values only.
• Without modification, these formats are not useful in scientific or
business applications that deal with real number values.
• Floating-point representation solves this problem.
72
2.5 Floating-Point Representation
• If we are clever programmers, we can perform floating-point
calculations using any integer format.
• This is called floating-point emulation, because floating point values
aren’t stored as such; we just create programs that make it seem as if
floating-point values are being used.
• Most of today’s computers are equipped with specialized hardware
that performs floating-point arithmetic with no special programming
required.
73
2.5 Floating-Point Representation
74
2.5 Floating-Point Representation
• Computers use a form of scientific notation for floating-point
representation
• Numbers written in scientific notation have three components:
75
2.5 Floating-Point Representation
• Computer representation of a floating-point number consists of three
fixed-size fields:
76
2.5 Floating-Point Representation
• The one-bit sign field is the sign of the stored value.
• The size of the exponent field determines the range of values that
can be represented.
• The size of the significand determines the precision of the
representation.
77
2.5 Floating-Point Representation
• We introduce a hypothetical “Simple Model” to explain the concepts
• In this model:
• A floating-point number is 14 bits in length
• The exponent field is 5 bits
• The significand field is 8 bits
78
2.5 Floating-Point Representation
• The significand is always preceded by an implied binary point.
• Thus, the significand always contains a fractional binary value.
• The exponent indicates the power of 2 by which the significand is
multiplied.
79
2.5 Floating-Point Representation
• Example:
– Express 3210 in the simplified 14-bit floating-point model.
• We know that 32 is 25. So in (binary) scientific notation 32 = 1.0 x 25
= 0.1 x 26.
– In a moment, we’ll explain why we prefer the second notation versus the
first.
• Using this information, we put 110 (= 610) in the exponent field and 1
in the significand as shown.
80
2.5 Floating-Point Representation
• The illustrations shown at the
right are all equivalent
representations for 32 using our
simplified model.
• Not only do these synonymous
representations waste space,
but they can also cause
confusion.
81
2.5 Floating-Point Representation
• Another problem with our system is that we have made no
allowances for negative exponents. We have no way to express 0.5
(=2 -1)! (Notice that there is no sign in the exponent field.)
84
2.5 Floating-Point Representation
• To provide for negative exponents, we will use a
biased exponent.
• A bias is a number that is approximately midway in
the range of values expressible by the exponent. We
subtract the bias from the value in the exponent to
determine its true value.
– In our case, we have a 5-bit exponent. We will use 16 for
our bias. This is called excess-16 representation.
• In our model, exponent values less than 16 are
negative, representing fractional numbers.
85
2.5 Floating-Point Representation
• Example:
• Express 3210 in the revised 14-bit floating-point model.
• We know that 32 = 1.0 x 25 = 0.1 x 26.
• To use our excess 16 biased exponent, we add 16 to 6, giving 2210
(=101102).
• So we have:
86
2.5 Floating-Point Representation
• Example:
• Express 0.062510 in the revised 14-bit floating-point model.
• We know that 0.0625 is 2-4. So in (binary) scientific notation 0.0625 =
1.0 x 2-4 = 0.1 x 2 -3.
• To use our excess 16 biased exponent, we add 16 to -3, giving 1310
(=011012).
87
2.5 Floating-Point Representation
• Example:
• Express -26.62510 in the revised 14-bit floating-point model.
• We find 26.62510 = 11010.1012. Normalizing, we have: 26.62510 =
0.11010101 x 2 5.
• To use our excess 16 biased exponent, we add 16 to 5, giving 2110
(=101012). We also need a 1 in the sign bit.
88
Exercises
• Express the following numbers in the revised 14-bit floating-point model:
• 0.0312510, 0 01100 1000000
• -100.2510
• 27.7510 0 01011 11011110
• Express the following numbers in floating-point model that assigns 1 bit for the sign, 3 bits for the exponent and 6
bits for the significand:
• -17.62510, non representable
• -8.7510 1 000 100011
• 5.2510 0 001 101010
• Give the equivalent in decimal for the following floating-point representations:
• 1 01110 10000000 .125
• 0 10100 10001001 8.5625
• 0 111 111111
• 1 000 000000
89