Information Security system Design Fundamentals third Week study summary

Source: Internet
Author: User

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

Three important types of digital tables:

1. Unsigned number: The encoding represents a number greater than or equal to zero, based on the traditional binary notation.

2. Complement: Encoding is the most common method of representing signed integers, which can be positive or negative numbers.

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

2.1 Information Storage

In C, a numeric constant beginning with 0x or 0X is considered to be a hexadecimal value.

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.

Each computer has a word length that indicates the nominal size of the integer and pointer data, 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-bit or 64-bit, it can also be understood as the number of bits of CPU processing data at a time.

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

The string in the C language is encoded as an array of characters ending with a null (value of 0) character. Use ASCII character codes more.

The same results can be obtained on any system that uses ASCII character codes, regardless of byte order and word size rules, so that text data has greater platform independence than binary data.

Binary code has different encoding rules on different operating systems, so binary code is incompatible, and binary code can rarely be ported between different machine and operating system combinations.

Boolean algebra:

Common operational symbols: with or non-XOR or

Extended in-place vector: a bit vector is a string with a fixed length of W, consisting of 0 and 1, and the operation of a bit vector can be defined as an operation between each corresponding element of the parameter.

A useful application of bit vectors is to represent a finite set.

A useful feature of the C language is the support for bitwise Boolean operations, and the best way to determine the results of a bit-level expression is to extend the hexadecimal parameter to binary and perform a binary operation before returning to Hex.

A common use of bit-level arithmetic is the mask operation, which is a bit pattern that represents the collection of bits selected from a single word.

The C language also provides a set of logical operators: | |,&&,! , respectively, corresponding to the or,and,not operation.

The difference between a logical operation and a bitwise operation

1.只有当参数被限制为0或1时,逻辑运算才与按位运算有相同的行为。

2.如果对第一个参数求值就能确定表达式的结果,逻辑运算符就不会对后面的参数求值

The C language also provides a set of shift operations.

2.2 Integer Representation

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.

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 negative values is 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.

Unsigned number encoding: Each number between 0~2^w-1 has a unique W-bit value encoding.

Complement code:

In the definition of the complement code, the most significant bit of the word is interpreted as negative, the most significant bit is also known as the sign bit, negative when set to 1, and positive when set to 0.

Note: The range of complement is asymmetrical,因为一半的数的整数一半是负数,而0是非负数,最大的无符号数值刚好比补码的最大值的两倍大一点。

There are two other standard representations of symbolic numbers: Inverse code and original code

2.3 Integer Arithmetic

1. Unsigned addition:

Can be considered as a modulo operation, equivalent to the calculation and modulo 2^w, in fact, the equivalent of discarding the highest bit overflow.

2. Complement addition:

It is important to note that you must determine how the result is too large or too small to be handled.

Negative overflow results are larger than integers and 16, and positive overflow results are 16 smaller than integers.

3. Complement of non-

4. Unsigned multiplication: Calculating product model 2^w

5. Complement multiplication:

The symbolic multiplication in C is achieved by truncating the product of the 2w bit to w bit. Represents an integer

For unsigned and complement multiplication, the bit-level representation of the multiplication is the same.

6. Multiply constants:

In machine operations, multiplication is always slow, while addition and displacement (left shift) are relatively fast. So in the compiler, a combination of shift and addition operations is used instead of multiplying the constant factor. This method is applicable for both unsigned and complementary operations.

When the recurses constant is 2, SHIFT + Add and subtract is used when the recurses is not 2.

Overflow does not affect the result.

7. The power of dividing by 2

For unsigned numbers, the logical right shift

For the complement, the arithmetic shifts right.

8. Summary

The "integer" operation performed by the computer is actually a modulo operation mode, which indicates that the finite word length of the number limits the range of possible values, the resulting operation may overflow, and it can be seen that the complement provides a flexible way to represent both positive and negative numbers, while using the same bit-level implementation as the execution of unsigned arithmetic.

2.4 Floating point

The floating-point representation encodes the rational number of a shape such as V=x x (2^y) for:非常大的数字,非常接近于0的数字,作为实数运算的近似值

1. Binary decimals

The decimal point is a positive power of 2 to the left and a negative power of 2 to the right.

2.IEEE floating point representation

Use v= ( -1) ^s x 2^E x M to represent a number:

Symbol: s Determines whether the number is positive or negative. 0 The sign bit special case processing.

Order code:E to the floating-point weighting, the weight is 2 of the e-power (may be negative)

Mantissa:m is a binary decimal with a range of 1~2-ε or 0~1-ε ( n-th power of Ε=1/2)

Divide the bit representation of a floating-point number into three fields and encode the values:

Individual sign bit s coded symbol S, accounting for 1 bits

K-Bit Order field exp coded order E

N-bit decimal segment frac encoded Mantissa M (the value of the dependent order field is also required to be 0)

Two types of accuracy:

Single precision (float), S=1 bit, k=8 bit, n=23 bit, altogether 32 bits;

Double precision (double), S=1 bit, k=11 bit, n=52 bit, altogether 64 bits.

Three types of cases:

1. Normalized values:

The bit mode of exp is neither 0 nor all 1, in which case the Order field is interpreted as a signed integer represented in a biased form.

Order E = E-bias (bias=[2^ (k-1)-1])

The binary decimal point is to the left of the most significant bit of the small number segment.

Mantissa m = 1+f (implied with 1-prefaced representation)

2. Non-normalized values

When the Order field is full 0 o'clock, the order E = 1-bias, the mantissa m = f (the value of the small number field, does not contain the implied 1)

Non-normalized provides a method for representing 0 and very close to 0 values

3. Special values

Order code full 1 o'clock.

One case is infinity, and one case is "not a number."

3. Rounding

The task of rounding operations is to find the closest matching value x ' to the value x ', which can be expressed in the desired floating-point form.

1. Rounding to even numbers

Rounds a number up or down so that the lowest effective number of the result is even.

2. Rounding to 0

3. Rounding up

4. Rounding Down

34 you can see the upper bound.

Rounding to even gets the closest match.

4. Floating-point arithmetic

Floating-point addition: exchangeable, non-associative, satisfying monotonicity

Floating-point multiplication: exchangeable, non-associative, non-assignable, satisfies the following monotonicity

Floating-point numbers in 5.c languages

When forcing type conversions between int,float,double formats, the program changes the values and bit patterns to the following principles:

from int to float: number does not overflow but may be rounded

from int or float to double: because double has a larger range and has higher precision, you can preserve precise values

From double to float: Because the range is smaller, values can overflow into positive or negative infinity, and may be rounded due to small precision

from float or double to int: value is rounded to 0

Information Security system Design Fundamentals third Week study summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.