πŸ›Ί

Chapter 2 Bits, Data Types, and Operations

bits

Computer is a binary digital system.

high voltage: 1; low voltage: 0

signed integers

n bits, 2n2^nο»Ώ distinct values, βˆ’2nβˆ’1∼2nβˆ’1βˆ’1-2^{n-1} \sim 2^{n-1}-1ο»Ώ

The maximal positive 011…1 (2nβˆ’1βˆ’12^{n-1}-1ο»Ώ)

The minimal: 100..000 (βˆ’2nβˆ’1-2^{n-1}ο»Ώ)

negative integers (3 methods):

Note: ignoring carry out (overflow)

1) How to get the representation of a signed integer? -9

2) How the get the decimal from binary representation? 11011

arithmetic operations: ADD, SUBTRACT, Sign Extension

logical operations: AND, OR, NOT

Sign Extension: replicate the sign bit

Fractions: fixed-point

Floating number

For very large or small numbers.

Scientific notation

1 (Sign) + 8 (Exponent, (exponent - 127)) + 23 (Fraction)

N=(βˆ’1)Sβˆ—1.fractionβˆ—2exponentβˆ’127,1≀exponent≀254N = (-1)^S* 1.fraction * 2^{exponent - 127}, 1 \le exponent \le 254ο»Ώ

N=(βˆ’1)Sβˆ—0.fractionβˆ—2βˆ’126,exponent=00000000N = (-1)^S * 0.fraction * 2^{-126}, exponent = 0000 0000ο»Ώ

See P47.

Logic operation

XOR: exclusive-OR

ABA XOR B
000
011
101
110

DeMorgan’s Laws (relationships between AND and OR)

NOT(NOT(A) AND NOT(B)) = A OR B

NOT(NOT(A) OR NOT(B)) = A AND B

ASCII: American Standard Code for Information Interchange