wisconsin
Chapter 2: Representing and Manipulating Information

Chapter 2: Representing and Manipulating Information

Content locked

The catalog is public. Reading this content requires approved access.

Sign in to read
Chapter 2: Representing and Manipulating Information
Representing and Manipulating Information
Aside How to read this chapter
2.1 Information Storage
Aside The evolution of the C programming language
New to C? The role of pointers in C
2.1.1 Hexadecimal Notation
Practice Problem 2.1 (solution page 179)
Practice Problem 2.2 (solution page 179)
Practice Problem 2.3 (solution page 180)
Aside Converting between decimal and hexadecimal
Practice Problem 2.4 (solution page 180)
2.1.2 Data Sizes
2.1.3 Addressing and Byte Ordering
Aside Origin of “endian”
New to C? Naming data types with typedef
New to C? Formatted printing with printf
New to C? Pointers and arrays
New to C? Pointer creation and dereferencing
Aside Generating an ASCII table
Practice Problem 2.5 (solution page 180)
Practice Problem 2.6 (solution page 181)
2.1.4 Representing Strings
Practice Problem 2.7 (solution page 181)
2.1.5 Representing Code
Aside The Unicode standard for text encoding
2.1.6 Introduction to Boolean Algebra
Practice Problem 2.8 (solution page 181)
Web Aside DATA:BOOL More on Boolean algebra and Boolean rings
Practice Problem 2.9 (solution page 182)
2.1.7 Bit-Level Operations in C
Practice Problem 2.10 (solution page 182)
Practice Problem 2.11 (solution page 182)
Practice Problem 2.12 (solution page 182)
Practice Problem 2.13 (solution page 183)
2.1.8 Logical Operations in C
Practice Problem 2.14 (solution page 183)
Practice Problem 2.15 (solution page 184)
2.1.9 Shift Operations in C
Practice Problem 2.16 (solution page 184)
Aside Shifting by k, for large values of k
Aside Operator precedence issues with shift operations
2.2 Integer Representations
2.2.1 Integral Data Types
2.2.2 Unsigned Encodings
PRINCIPLE: Uniqueness of unsigned encoding
2.2.3 Two’s-Complement Encodings
PRINCIPLE: Definition of two’s-complement encoding
PRINCIPLE: Uniqueness of two’s-complement encoding
Practice Problem 2.17 (solution page 184)
Aside More on fixed-size integer types
Aside Alternative representations of signed numbers
Practice Problem 2.18 (solution page 185)
2.2.4 Conversions between Signed and Unsigned
Practice Problem 2.19 (solution page 185)
Practice Problem 2.20 (solution page 185)
2.2.5 Signed versus Unsigned in C
Practice Problem 2.21 (solution page 185)
2.2.6 Expanding the Bit Representation of a Number
Web Aside DATA:TMIN Writing TMin in C
Practice Problem 2.22 (solution page 186)
Practice Problem 2.23 (solution page 186)
2.2.7 Truncating Numbers
PRINCIPLE: Truncation of an unsigned number
DERIVATION: Truncation of an unsigned number
PRINCIPLE: Truncation of a two’s-complement number
DERIVATION: Truncation of a two’s-complement number
Practice Problem 2.24 (solution page 186)
2.2.8 Advice on Signed versus Unsigned
Practice Problem 2.25 (solution page 187)
Practice Problem 2.26 (solution page 187)
2.3 Integer Arithmetic
2.3.1 Unsigned Addition
Aside Security vulnerability in getpeername
Aside Security vulnerability in getpeername (continued)
DERIVATION: Unsigned addition
PRINCIPLE: Detecting overflow of unsigned addition
Practice Problem 2.27 (solution page 188)
PRINCIPLE: Unsigned negation
DERIVATION: Unsigned negation
Practice Problem 2.28 (solution page 188)
2.3.2 Two’s-Complement Addition
PRINCIPLE: Two’s-complement addition
DERIVATION: Two’s-complement addition
PRINCIPLE: Detecting overflow in two’s-complement addition
DERIVATION: Detecting overflow of two’s-complement addition
Practice Problem 2.29 (solution page 188)
Practice Problem 2.30 (solution page 189)
Practice Problem 2.31 (solution page 189)
Practice Problem 2.32 (solution page 189)
2.3.3 Two’s-Complement Negation
PRINCIPLE: Two’s-complement negation
DERIVATION: Two’s-complement negation
Practice Problem 2.33 (solution page 189)
Web Aside DATA:TNEG Bit-level representation of two’s-complement negation
2.3.4 Unsigned Multiplication
2.3.5 Two’s-Complement Multiplication
Practice Problem 2.34 (solution page 189)
Practice Problem 2.35 (solution page 190)
Practice Problem 2.36 (solution page 190)
Practice Problem 2.37 (solution page 191)
Aside Security vulnerability in the XDR library
2.3.6 Multiplying by Constants
PRINCIPLE: Multiplication by a power of 2
DERIVATION: Multiplication by a power of 2
PRINCIPLE: Unsigned multiplication by a power of 2
PRINCIPLE: Two’s-complement multiplication by a power of 2
Practice Problem 2.38 (solution page 191)
Practice Problem 2.39 (solution page 192)
Practice Problem 2.40 (solution page 192)
Practice Problem 2.41 (solution page 192)
2.3.7 Dividing by Powers of 2
PRINCIPLE: Unsigned division by a power of 2
DERIVATION: Unsigned division by a power of 2
PRINCIPLE: Two’s-complement division by a power of 2, rounding up
DERIVATION: Two’s-complement division by a power of 2, rounding up
Practice Problem 2.42 (solution page 192)
Practice Problem 2.43 (solution page 193)
2.3.8 Final Thoughts on Integer Arithmetic
Practice Problem 2.44 (solution page 193)
2.4 Floating Point
Aside The IEEE
2.4.1 Fractional Binary Numbers
Practice Problem 2.45 (solution page 193)
Practice Problem 2.46 (solution page 194)
2.4.2 IEEE Floating-Point Representation
Case 1: Normalized Values
Aside Why set the bias this way for denormalized values?
1. Normalized
2. Denormalized
3a. Infinity
3b. NaN
Case 2: Denormalized Values
Case 3: Special Values
2.4.3 Example Numbers
Practice Problem 2.47 (solution page 194)
Practice Problem 2.48 (solution page 195)
Practice Problem 2.49 (solution page 195)
2.4.4 Rounding
Practice Problem 2.50 (solution page 195)
Practice Problem 2.51 (solution page 195)
Practice Problem 2.52 (solution page 196)
1. Format A
2. Format B
2.4.5 Floating-Point Operations
2.4.6 Floating Point in C
Practice Problem 2.53 (solution page 196)
Practice Problem 2.54 (solution page 196)
2.5 Summary
Aside Ariane 5: The high cost of floating-point overflow
Bibliographic Notes
Homework Problems
2.55 ◆
2.56 ◆
2.57 ◆
2.58 ◆◆
2.59 ◆◆
2.60 ◆◆
Bit-Level Integer Coding Rules
2.61 ◆◆
2.62 ◆◆◆
2.63 ◆◆◆
2.64 ◆
2.66
2.67
2.68 ◆◆
2.69 ◆◆◆
2.70 ◆◆
2.71 ◆
2.72 ◆◆
2.74
2.75
2.76
2.77 ◆◆
2.78 ◆◆
2.79 ◆◆
2.80 ◆◆◆
2.81 ◆◆
2.82 ◆
2.83 ◆◆
2.84 ◆
2.85 ◆
2.86 ◆
2.87 ◆
2.88 ◆◆
1. Format A
2. Format B
2.89 ◆
2.90
2.91 ◆
Bit-Level Floating-Point Coding Rules
2.92 ◆◆
2.94
2.95
2.96
2.97 ◆◆◆◆
Solutions to Practice Problems
Solution to Problem 2.1 (page 73)
Solution to Problem 2.2 (page 73)
Solution to Problem 2.3 (page 74)
Solution to Problem 2.4 (page 75)
Solution to Problem 2.5 (page 84)
Solution to Problem 2.6 (page 85)
Solution to Problem 2.7 (page 85)
Solution to Problem 2.8 (page 87)
Solution to Problem 2.9 (page 89)
Solution to Problem 2.10 (page 90)
Solution to Problem 2.11 (page 91)
Solution to Problem 2.12 (page 91)
Solution to Problem 2.13 (page 92)
Solution to Problem 2.14 (page 93)
Solution to Problem 2.15 (page 93)
Solution to Problem 2.16 (page 94)
Solution to Problem 2.17 (page 101)
Solution to Problem 2.18 (page 105)
Solution to Problem 2.19 (page 107)
Solution to Problem 2.20 (page 109)
Solution to Problem 2.21 (page 112)
Solution to Problem 2.22 (page 115)
Solution to Problem 2.23 (page 116)
Solution to Problem 2.24 (page 118)
Solution to Problem 2.25 (page 119)
Solution to Problem 2.26 (page 119)
Solution to Problem 2.27 (page 125)
Solution to Problem 2.28 (page 125)
Solution to Problem 2.29 (page 129)
Solution to Problem 2.30 (page 130)
Solution to Problem 2.31 (page 130)
Solution to Problem 2.32 (page 130)
Solution to Problem 2.33 (page 131)
Solution to Problem 2.34 (page 134)
Solution to Problem 2.35 (page 135)
Solution to Problem 2.36 (page 135)
Solution to Problem 2.37 (page 135)
Solution to Problem 2.38 (page 138)
Solution to Problem 2.39 (page 139)
Solution to Problem 2.40 (page 139)
Solution to Problem 2.41 (page 139)
Solution to Problem 2.42 (page 143)
Solution to Problem 2.43 (page 143)
Solution to Problem 2.44 (page 144)
Solution to Problem 2.45 (page 147)
Solution to Problem 2.46 (page 147)
Solution to Problem 2.47 (page 153)
Solution to Problem 2.48 (page 155)
Solution to Problem 2.49 (page 156)
Solution to Problem 2.50 (page 157)
Solution to Problem 2.51 (page 158)
Solution to Problem 2.52 (page 158)
Solution to Problem 2.53 (page 161)
Solution to Problem 2.54 (page 161)