the representation and processing of the information in the 2nd Chapter

**(i), three kinds of important digital representations**

Unsigned number: The encoding is based on the traditional binary notation (numbers greater than or equal to zero).

Complement: Encoding is the most common way to represent signed integers (numbers that are positive or negative).

Floating-point number: The encoding is a two-base version of the scientific notation for real numbers.

Although the representation of an integer can only encode a relatively small range of values, it is accurate, while floating-point numbers may encode a larger range of values, but this representation is an approximate representation.

A large number of computer security vulnerabilities are caused by the subtle details of computer operations.

**(ii), information storage**

The smallest addressable memory unit of a computer- **byte**

Domain value of one byte: 00h-ffh

16 or 16 binary notation1. C notation

A numeric constant that starts with **0x** or **0X** is hexadecimal

2. Binary conversion

Common binary: Binary (B), Decimal (D), octal (o or Q), Hex (H)

Converts to binary-16 binary, with binary four digits corresponding to a hexadecimal digit.

In the same vein, the binary and octal conversions are three-bit counterparts.

In general, however, the conversion of the binary is converted into a bridge with a binary system.

**Note: Special cases**

Textbook Page 23 There is a case where the numeric constants to be represented are x=2 n times, n=i+4j, and 0≤i≤3, the hexadecimal digits at the beginning are 1 (i=0), 2 (I=1), 4 (i=2), 8 (i=3), followed by the J hexadecimal 0. The J here represents the hexadecimal bits corresponding to each of the four-bit bits, and the range of I is because the range of each bit in hexadecimal is 0-f, which can accommodate up to 8. This is a convenient and quick calculation method.

Second, the word

The word length determines the maximum size of the virtual address space.

The word length is w and the virtual address range is (2^w-1)

W=32 or 64: That is, what we usually call a computer is 32 or 64 bits. It can also be understood as the number of bits that the CPU processes data at a time.

third, data size

In different lengths of the computer, the same data types occupy the same number of bytes, 32-bit and 64-bit differences see the Textbook 26 page table.

`gcc -m32 可以在64位机上生成32位的代码`

Iv. Addressing and byte order1. Small-end method and big-endian method

- Small End method: Minimum valid byte in front--"high to high, low to Low"
- Big- endian: Maximum valid byte in front 2. Forcing type conversions
- typedef: Named Data types
- sizeof (): Returns the number of bytes of a type (benefits?) Easy to transplant-32-bit and 64-bit differences)

**V. to represent a string**

The string in C is encoded as an array of characters ending with a null (value of 0) character

Command man ASCII: Get ASCII character code table

**Vi. Code of presentation**

Binary code has different encoding rules on different operating systems. So the binary code is incompatible

**Seven, Boolean algebra**

1. Simplest Boolean algebra: With & or | Non-XOR ^ (result 0 or 1)

2. Extended Boolean operation: Bitwise VECTOR operation (the result is still a bit vector)

Application of bit vectors: representing a finite set, encoding a set

**Eight, bit-level arithmetic**

1. Bitwise logical operation of the bit vector, the result is still a bit vector

2. Mask operation

Mask: Used to selectively mask a signal, is a bit pattern that represents a collection of bits selected from a word.

A bit vector is used to encode the set, by specifying a mask to selectively mask or not shielding some signals, a position of 1 o'clock, indicating that the signal i is valid; 0 indicates that the signal is blocked. This mask represents a collection of valid signals.

0xFF: Masks All bytes except the least significant byte.

~0: Generate a full 1 mask

**Nine, logical operation**

1. Logical operators: With && or | | Non -!

2. Calculation method: All non-0 parameters represent false for the true,0 parameter. 1 for true,0 rep false

- A logical operation has the same behavior as a bitwise operation only if the parameter is limited to 0 or 1 o'clock.
- If the first parameter is evaluated to determine the result of the expression, the logical operator does not evaluate the subsequent parameters.

**Ten, shift operation**

1. Shift left <<

2. Move Right >>

Logical right Shift: Fill K 0 at left, more for unsigned number shift operations

Arithmetic right Shift: A value that complements K's most significant bits at the left, and is used more for signed number shift operations.

- Use
**>>** for arithmetic right shift in Java, with **>>>** for logical right Shift
- Shift operation priority is less than arithmetic operation

(c)

**,** integer representationfirst, the integer data type

Integer data types-integers that represent a finite range, each of which can specify a size with a keyword, and can specify a non-negative (unsigned) or negative (default). The number of words for these different sizes will vary depending on the length of the machine and the compiler.

**About range of values**

- A
**typical** range of values for the same data type is different for 32-bit machines and 64-bit machines.
- In a typical range of values, the range of values is
**asymmetric** -negative ranges are 1 larger than the range of integers.
- The C language standard defines that each data type must be able to represent the smallest range of
**values** in which the range of positive and negative values is **symmetric** .

See page 38 for the specific scope of the book.

`要用C99中的“long long”类型，编译是要用 gcc -std=c99`

two, unsigned number of code

The coding method is seen in books and has been studied in many subjects.

It is important to note that the binary representation of an unsigned number is of a *significant nature* :

0-(2^w)-each integer in 1 and a bit vector with a length of W are **one by one corresponding** .

Three, complementary code--signed number of the code

About the complement, some knowledge that may not have been noticed:

- We all know that the highest bit of the complement is the representation of the sign bit, interpreted as a
**negative right** , the "weight" of-2 (w-1), that is, the negative number of the weight in the unsigned representation. The sign bit is 1, the value is negative, the sign bit is 0, the value is **non-negative** (not positive, because there are 0)
- The mapping of the complement is also
**one by one corresponding**
- Complement range: -2^ (w-1) ~2^ (w-1)-1, i.e. | tmin|=| tmax|+1--because of the presence of 0 in non-negative numbers.
- Unsigned number encoding (U) and complement (T): UMax = 2 TMax + 1
- In most cases, the signed number is represented by the complement and has a
**typical** range of values.

Other representations of the signed number:

Iv. Conversion of signed and unsigned numbers1. Forcing type conversions

Consider from a **bit-level** perspective.

Forcing the result of a type conversion holds the bit value unchanged, only changing the way that these bits are interpreted. That is, the values on these bits do not change, but the weights of the most significant bits change, resulting in a change in the results.

signed numbers and unsigned numbers in 2.c languages and their conversionsconversion principle: the underlying bits remain unchanged. (1) signed number → unsigned number

- Non-negative--remains the same
Negative number--converts to a large positive number

(2) unsigned number → signed numberThe w-1 of 2 is the limit:

- Less than it--remains the same
Greater than--converted to a negative value

**Vi. extending the bit representation of a number**

Extension: Converts from a smaller data type to a larger data type while keeping the value constant.

1.0 Extension: Add 0 at the beginning. Many are used to convert unsigned numbers to a larger data type.

2. Symbol extension: Add a copy of the most significant bit. More for complement digital conversions

**VII. Truncation**

Truncation: Reduces the number of digits that represent a number. Doing so may change its value, which is also a form of **overflow** .

When the number of a w bit is truncated to a K-bit number, the high w-k bit is discarded.

- For
**unsigned** numbers, it's equivalent to the K-Power of MoD 2.
- For
**signed** numbers, the number of unsigned numbers is truncated before being converted to the signed number

(iv)

**,** floating point

The floating-point representation encodes the **rational number** of a shape such as V=x x (2^y) for:

`非常大的数字非常接近于0的数字作为实数运算的近似值`

one or two decimal

The binary representation of decimals can only represent those that can be written as x x (2^y), and the other values can only be **approximated** .

**Weight**

The decimal point is the boundary:

`左边第i位，权重为2的i次幂右边第i位，权重为1/2的i次幂`

Second, IEEE floating point representationIEEE floating point standard:

`用V=(-1)^s X 2^E X M 来表示一个数：符号：s决定这个数是正还是负。0的符号位特殊情况处理。阶码：E对浮点数加权，权重是2的E次幂（可能为负数）尾数：M是一个二进制小数，范围为1~2-ε或者0~1-ε（ε=1/2的n次幂）`

Encoding Rules:

`单独符号位s编码符号s，占1位k位的阶码字段exp编码阶码En位小数字段frac编码尾数M（同时需要依赖阶码字段的值是否为0）`

two types of accuracy

- Single precision (float), k=8 bit, n=23 bit, altogether 32 bits;
- Double precision (double), k=11 bit, n=52 bit, altogether 64 bits.

1. Normalized values

That is, the EXP bit mode is not all 0 or 1, this is the most general and most common situation, and thus is normalized.

2. Non-normalized values

That is, the Order field is a total of 0 o'clock.

3. Special Values

The special value appears when the order code bit is all 1. There are two types of situations:

(1) Infinity

The small number field is all 0

(2) Nan is not a number

Small number field not 0

Third, rounding

**Rounding** operations: finds the closest matching value x ' to the value x ', which can be expressed in the desired floating-point form.

The IEEE floating-point format defines four different rounding methods:

1. Rounding to even (default method)

That is, the number is rounded up or down, and the lowest valid number of the result is even.

Can be used in binary decimals.

2. Rounding to 0

That is, rounding down integers and negative numbers rounded up.

3. Rounding down

Both positive and negative numbers are rounded down.

4. Rounding up

Both positive and negative numbers are rounded up.

Iv. Floating-point arithmetic1. Floating-point addition

- Floating-point addition is exchangeable
- Floating point addition not binding
- The floating-point addition of most values has an inverse, except for infinity and Nan.
- Floating-point addition satisfies monotonicity

2. Floating-point multiplication

- Floating-point multiplication is exchangeable
- Floating-point multiplication does not have tuberculous
- The unit of floating-point multiplication is 1.0
- Floating-point multiplication is not assignable on addition

floating-point numbers in the C language

int, float, double convert each other?

`int→ float does not overflow but it is possible to round int/float→ double→ float may overflow to ±∞, due to the small accuracy may be rounded float/double→ `

` `

` `

**problems encountered**
What are the differences between bit patterns and bit vectors?

P32 page: Bit vectors are vectors made up of some bits. Bit vectors can store Boolean variables in very little memory.

` `

Information Security system Design Fundamentals third Week study summary