Chapter2 5
Chapter2 5
2
Binary Representation of Numbers
Any integer greater than 1 can serve as a base for a
number system. In computer science, base 2 notation, or
binary notation, is of special importance because the
signals used in modern electronics are always in one of
only two states. (The Latin root bi means “two.”)
3
Example 2.5.1 – Binary Notation for Integers from 1 to 9
4
Example 2.5.1 – Solution
5
Binary Representation of Numbers
A list of powers of 2 is useful for doing binary-to-decimal
and decimal-to-binary conversions.
Powers of 2
Table 2.5.1
6
Example 2.5.2 – Converting a Binary to a Decimal Number
7
Example 2.5.2 – Solution
8
Example 2.5.3 – Converting a Decimal to a Binary Number
9
Example 2.5.3 – Solution
Use Table 2.5.1 to write 209 as a sum of powers of 2,
starting with the highest power of 2 that is less than 209
and continuing to lower powers.
Powers of 2
Table 2.5.1
10
Example 2.5.3 – Solution continued
11
Example 2.5.3 – Solution continued
12
Binary Addition and Subtraction
13
Binary Addition and Subtraction
The computational methods of binary arithmetic are
analogous to those of decimal arithmetic. In binary
arithmetic the number 2 (which equals in binary
notation) plays a role similar to that of the number 10 in
decimal arithmetic.
14
Example 2.5.4 – Addition in Binary Notation
15
Example 2.5.4 – Solution
Because the translation of
to binary notation is
16
Example 2.5.4 – Solution continued
17
Example 2.5.5 – Subtraction in Binary Notation
18
Example 2.5.5 – Solution
In decimal subtraction the fact that is used
to borrow across several columns.
19
Example 2.5.5 – Solution continued
20
Two’s Complements and the
Computer Representation
of Signed Integers
21
Two’s Complements and the Computer Representation of Signed Integers
22
Two’s Complements and the Computer Representation of Signed Integers
23
Two’s Complements and the Computer Representation of Signed Integers
24
Two’s Complements and the Computer Representation of Signed Integers
25
Example 2.5.6 – Finding a Two’s Complement
26
Example 2.5.6 – Solution
Write the 8-bit binary representation for switch
all the 1’s to 0’s and all the 0’s to 1’s, and then add 1.
27
Two’s Complements and the Computer Representation of Signed Integers
28
Two’s Complements and the Computer Representation of Signed Integers
29
Two’s Complements and the Computer Representation of Signed Integers
Moreover, because the bits are switched, the leading bit for
all the negative integers is 1.
30
Two’s Complements and the Computer Representation of Signed Integers
Table 2.5.2
31
Two’s Complements and the Computer Representation of Signed Integers
32
Example 2.5.7 – Finding a Number with a Given Two’s Complement
33
Example 2.5.7 – Solution
Since the left-most digit is 1, the integer is negative.
Applying the two’s complement procedure gives the
following result:
34
Addition and Subtraction with
Integers in Two’s Complement
Form
35
Addition and Subtraction with Integers in Two’s Complement Form
36
Addition and Subtraction with Integers in Two’s Complement Form
37
Addition and Subtraction with Integers in Two’s Complement Form
38
Addition and Subtraction with Integers in Two’s Complement Form
39
Hexadecimal Notation
40
Hexadecimal Notation
Hexadecimal notation is even more compact than decimal
notation, and it is much easier to convert back and forth
between hexadecimal and binary notation than it is
between binary and decimal notation.
The word hexadecimal comes from the Greek root hex-,
meaning “six,” and the Latin root deci-, meaning “ten.”
Hence hexadecimal refers to “sixteen,” and hexadecimal
notation is also called base 16 notation.
41
Hexadecimal Notation
Hexadecimal notation is based on the fact that any integer
can be uniquely expressed as a sum of numbers of the
form
42
Hexadecimal Notation
The 16 hexadecimal digits are shown in Table 2.5.3,
together with their decimal equivalents and, for future
reference, their 4-bit binary equivalents.
Table 2.5.3
43
Example 2.5.8 – Converting from Hexadecimal to Decimal Notation
44
Example 2.5.8 – Solution
A schema similar to the one introduced in Example 2.5.2
can be used here.
45
Hexadecimal Notation
46
Example 2.5.9 – Converting from Hexadecimal to Binary Notation
47
Example 2.5.9 – Solution
Consequently,
48
Hexadecimal Notation
To convert integers written in binary notation into
hexadecimal notation, reverse the steps of the previous
procedure. Note that the commonly used computer
representation for integers uses 32 bits. When these
numbers are written in hexadecimal notation only eight
characters are needed.
49
Example 2.5.10 – Converting from Binary to Hexadecimal Notation
50
Example 2.5.10 – Solution
First group the binary digits in sets of four, working from
right to left and adding leading 0’s if necessary.
51
Example 2.5.10 – Solution continued
52
Example 2.5.11 – Reading a Memory Dump
53
Example 2.5.11 – Solution
54