Algorithms and Data Structures in C part 5 - Pdf 16



Figure 1.2 Memory Implementation for Variable t

Figure 1.3 Mapping of each Union Entry
The organization of each union entry is shown in Figure 1.3. For the union declaration t there are
only eight bytes stored in memory. These eight bytes can be interpreted as eight individual
characters or two longs or two doubles, etc. For instance by looking at Table 1.8 one sees the
value of ch[0] which is 0×41 which is the letter A. Similarly, the value of ch[1] is 0×42 which is
the letter B. When interpreted as an integer the value of i[0] is 0×41424344 which is in 2’s
complement format. Converting to decimal one has i[0] with the value of

If one were to interpret 0×41424344 as an IEEE 32-bit floating point number its value would be
12.1414. If one were to interpret 0×45464748 as an IEEE 32-bit floating point number its value
would be 3172.46.
Code List 1.15 Data Representations

Code List 1.16 Output of Program in Code List 1.15 There are only one’s and zero’s stored in memory and collections of bits can be interpreted to be
characters or integers or floating point numbers. To determine which kind of operations to
perform the compiler must be able to determine the type of each operation.
1.5 Problems
(1.1) Represent the following decimal numbers when possible in the format specified.
125, -1000, 267, 45, 0, 2500. Generate all answers in HEX!
a) 8-bit 2’s complement—2 hex digits
b) 16-bit 2’s complement—4 hex digits
c) 32-bit 2’s complement—8 hex digits
d) 64-bit 2’s complement—16 hex digits


Copyright © CRC Press LLC

Algorithms and Data Structures in C++
by Alan Parker
CRC Press, CRC Press LLC
ISBN: 0849371716 Pub Date: 08/01/93

Previous
 TableofContents Next

Chapter 2
Algorithms
This chapter presents the fundamental concepts for the analysis of algorithms.
2.1 Order
N denotes the set of natural numbers, {1, 2, 3, 4, 5, . . .}.
Definition 2.1
A sequence, x, over the real numbers is a function from the natural numbers into the real
numbers:

x
1
is used to denote the first element of the sequence, x(1) In general,

and will be written as
Unless otherwise noted, when x is a sequence and f is a function of one variable, f(x), is the
sequence obtained by applying the function f to each of the elements of x. If

then
For example,
Definition 2.2


n=1 n=10 n=100 n=1000 n=10000
log(n) 0 3.32 6.64 9.97 13.3
nlog(n) 0 33.2 664 9.97×10
3
 1.33×10
5

n
2
 1 100 10000 1×10
6
 1×10
8

n
5
 1 1×10
5
 1×10
10
 1×10
15
 1×10
20

e
n

2.7

2.85×10
3565
9



Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status