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: rr

digit: An−1An−2...A1A0.A−1A−2...A−m+1A−mA_{n-1}A_{n-2}...A_1A_0.A_{-1}A_{-2}...A_{-m+1}A_{-m}

(100101.01)2=25+22+20+2−2=(37.25)10(100101.01)_2=2^5+2^2+2^0+2^{-2}=(37.25)_1\kern{}_0

Arithmetic Operators

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division

 

Chapter 03 Representation of Numeric Data

Integer

Focus on binary number with N Bits ( called XT{X_T} )

XT=Xn−1Xn−2…X1X0X_T=X_{n-1}X_{n-2}…X_1X_0

Encoding Methods of Integers

Original code

use Xn−1X_{n-1} as signature

0 owns two representations — +0 & -0

Complement code ( IMPORTANT )

Eg in 12 o’clock

10−4=610 - 4 = 6

10+8=18≡6(mod 12)10 + 8 = 18 \equiv 6 ( \mathrm{mod}\ 12 )

Definition ∀XT:[XT]C=M+XT(mod M)\forall X_T: [X_T]_C=M+X_T(\mathrm{mod}\ M)

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 [XT]C[X_T]_C to [−XT]C[-X_T]_C:
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

−1→−0→+0→1-1\rightarrow -0\rightarrow+0\rightarrow 1

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

竖式累加的时候用第一位的数字补足每个乘出来的中间数字成一个相同长度的数字,乘数的符号位乘以被乘数时需要取反后加一

0053

 

Chapter 05 Floating-Point Number Representation & Non-Numeric Data

IEEE Standard 754

Numerical Form: (−1)sM⋅2E\mathrm{(-1)^sM\cdot2^E}

  • 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 2n−22^{n-2} (or frameshift by (n−2)(n-2) 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, E=exp−biasE=exp-bias

 

Normalized Encoding

Value: 15213.010=1.11011011011012×21315213.0_1\kern{}_0=1.1101101101101_2\times2^{13}

Significand

  • M = 1.110110110110121.1101101101101_2
  • frac = 1101101101101000…021101101101101000…0_2

Exponent

  • E = 1313
  • Bias = 127(=28−1)127(=2^{8-1})
  • Exp = 140140 = 10001100210001100_2

Result

  • 0∣10001100∣1101101101101000...00 | 10001100 | 1101101101101000...0

 

Denormalized Values & Encoding

In normalized value range, number lower than 1.0×2−1261.0\times 2^{-126} 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 0.100…20.100…_2 but not 1.100…21.100…_2, and meanwhile the Exp is 000…02000…0_2 which means ×2(−(n−2))10\times2(^{-(n-2)})_1\kern{}_0

normalized value cannot represent ZERO without denormalized version

  1. exp=000…0;frac=000…0exp = 000…0; frac = 000…0: Zero
  2. exp=000…0;frac≠000…0exp = 000…0; frac \ne 000…0: Numbers close to zero
  3. exp=111…1;frac=000…0exp = 111…1; frac = 000…0: INF (infinity)
  4. exp=111…1;frac≠000…0exp = 111…1; frac \ne 000…0: NaN (Not-a-Number)

1 & 2 show denormalized values whie 3 & 4 show another two special values

0054

 

Special Properties

  • FP Zero same as Integer Zero
  • Can (Almost) Use Unsigned Integer Comparison
    • Must consider 0=−00 = -0
    • 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

 

Data Width & Storage

公告
Welcome to Vanadium's Blog!
ZJUer | Freshman | IS | 术力口 | 摸鱼