Basic Infomation
Teachers: wht, ll
Lab Docs: 浙江大学24年春夏系统贯通一实验( ZJU intranet required )
Because of some reasons, Chapter 04 should change position with Chapter 05
Chapter 02 Binary Number Representation
Data represantation
Carry Counting System
radix:
digit:
Arithmetic Operators
- Addition
- Subtraction
- Multiplication
- Division
Chapter 03 Representation of Numeric Data
Integer
Focus on binary number with N Bits ( called )
Encoding Methods of Integers
Original code
use as signature
0 owns two representations — +0 & -0
Complement code ( IMPORTANT )
Eg in 12 o’clock
Definition
The Conversion from Complement code to true value:
- If the sign bit is 0 / the number is positive:
The value part does not need to be changed - Else the sign bit is 1 / the number is negative:
Invert the bits of value part, and add 1 to the result
From to :
Invert every bits, and add 1 to to the result
Advantages ( compared with sign-magnitude ):
- No +0 or -0 anymore
- Hardware simplicity
Inverse code
Complexity and uselessness in modern computer
Difference with the complement code Just invert, no add
Frameshift code ( more used in float numbers )
TBD
Representation of Integers
Bit-Level Operation in C
Bit Operations & | ~ ^ are available in C
Shifting Operations
- Left shift
x << y
Fill with 0 on right - Right shift
x >> y
Fill with 0 on left ( Logical shift )
Fill with 0 if positive or 1 if negative ( Arithmetic shift ) - Undefined Behaviour
Shift amount < 0 or >= word size
Multiplication
竖式累加的时候用第一位的数字补足每个乘出来的中间数字成一个相同长度的数字,乘数的符号位乘以被乘数时需要取反后加一
Chapter 05 Floating-Point Number Representation & Non-Numeric Data
IEEE Standard 754
Numerical Form:
- Sign bit s determines positive or negative
- M is in range [1.0, 2.0)
- Exponent E weights value by power 2
Precision
- Single precision 32 bits: s=1; exp = 8; frac = 23
- Double precision 64 bits: s = 1; exp = 11; frac = 52
- Extended precison 80 bits (Intel only)
Exponent (Frameshift Code)
Before calculation, times each number by (or frameshift by bits), and divide the same number after calculation
the goal is to escape from the case of “deviding zero” and etc.
When turn the component number to the true number,
Normalized Encoding
Value:
Significand
- M =
- frac =
Exponent
- E =
- Bias =
- Exp = =
Result
Denormalized Values & Encoding
In normalized value range, number lower than is missing and undefined
In denormalized value range, numbers in than such range definates different meanings
Additionly, M in denormalized values will be regarded as but not , and meanwhile the Exp is which means
normalized value cannot represent ZERO without denormalized version
- : Zero
- : Numbers close to zero
- : INF (infinity)
- : NaN (Not-a-Number)
1 & 2 show denormalized values whie 3 & 4 show another two special values
Special Properties
- FP Zero same as Integer Zero
- Can (Almost) Use Unsigned Integer Comparison
- Must consider
- Must first compare sign bits
- NaNs problematic
FP Operations
Rounding
Rounding Modes
- Towards zero
- Round down / floor()
- Round up / ceil()
- Nearest Even (default)
FP Addition
turn the smaller M to the bigger one, and shift the E
FP addition is NOT associative compared with Abelian Group
FP Mulitiplication
easy
M = M1 * M2
E = E1 + E2
FP mulitiplication is NOT associative or distributed over additions compared with Abelian Group
Non-Numeric Data
Logical Value
Alphanumeric Code
- ASCII : 7bit per char
- Unicode : 2Byte per char
- Chinese Character
- Input Code
- Internal Code
- Font Code