Information Security system Design Fundamentals third Week study summary

Source: Internet
Author: User
Tags truncated

Chapter II Representation and processing of information

    • Three types of numbers: unsigned, signed (2 complement), floating-point number
    • Overflow: The representation of a computer is to encode a number with a finite number of bits, which overflows when the result is too large to be represented
    • Integer arithmetic: The numeric range of coding is small, precise; floating-point arithmetic: Large range of values, approximate, non-binding

§1 Information Store

    • Smallest addressable Memory Unit: bytes (8 bits)
    • Virtual memory, address, virtual address space (P22)

16 or 16 binary notation

The domain value of one byte in hexadecimal is 00H~FFH

Hexadecimal numeric constants that start with 0x or 0X

    • Binary conversion

Shortcut algorithm: to represent a numeric constant of x=2^n,n=i+4j, and 0≤i≤3, the initial hexadecimal number is 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

Second, the word

Word length: Indicates the nominal size of the integer and pointer data. Determine the maximum size of the virtual address space

The word length is W, the virtual address range is 0~2^w-1, the program accesses up to 2^w bytes, and the CPU processes w bit data at a time

Third, data size

In computers of different lengths, the same data types occupy different numbers of bytes

Generate 32-bit code on a 64-bit machine: gcc-m32

Iv. Addressing and byte order

Multiple-byte objects are stored as contiguous sequence of bytes, with the address of the object being the smallest address in the byte used

Byte order is the basis of network programming

1. Two general rules (W is an integer, bits are expressed as [Xw-1,xw-2,......, x1,x0], where Xw-1 is the most significant bit and X0 is the least significant bit):

    • Small End method: least significant byte in front (most Intel compatible machines)
    • Big-endian: The most significant bytes in front (most IBM and Sun Microsystems machines)
    • Some new microprocessors use a double-ended method

The order of the bytes inside is constant

Disassembler: A tool that determines the sequence of instructions represented by an executable program file; the degree to which the executable program file is converted back to a more readable ASCII format

2. Forcing type conversions

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

§2 integer Representation

First, the integer data type

Integer data type--integers representing a limited range

To use the "long Long" type in ISO C99, compile with gcc-std=c99

Two, unsigned number encoding

An important property of the binary representation of an unsigned number: 0-(2^w)-1 each integer and a bit vector with a length of W are one by one corresponding

Three, complementary code

Complement range: -2^ (w-1) ~2^ (w-1)-1

Each number within the range of values that can be represented has a unique W-bit complement code

    • Other representations of signed numbers: Anti-code, original code

The complement uses the length of the register as a fixed feature to simplify the mathematical operation

Iii. conversions between signed and unsigned numbers

Coercion type conversions: Results hold the bit values unchanged, just changing the way that these bits are interpreted

function u2t: From unsigned number to complement; T2U: from complement to unsigned number

Signed and unsigned numbers in the C language

Unsigned constant: suffix character u or u

1. Conversion principle: The underlying bit remains the same

(1) signed number → unsigned number

Non-negative--remains the same

Negative number--converts to a large positive number

(2) unsigned number → signed number

With 2^* (w-1) as the boundary:

Less than it--remains the same

Greater than--converted to a negative value

[0,2^ (W-1)) in the range of numbers, unsigned and complementary expression of the same, outside the range, need to add or subtract 2^w

2. If there are both signed and unsigned numbers at the time of operation, the signed number coercion type is implicitly converted to the unsigned number, and the two numbers are assumed to be non-negative.

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

Viii. Summary

The unsigned number is applied to a set of bits without any numeric meaning, such as an address, or when a number is represented by an array of words when a modulo operation or a multi-precision operation is implemented.

§3 integer Arithmetic

One, unsigned addition (modulo operation)

Equivalent to calculation and mod2^w, directly discarding the highest bit represented by the w+1 bit of x+y

Second, complement addition

Essence: Modulus of the W-position of the complement of the most significant bit weights 2 of the power of W

Result: positive overflow, normal, negative overflow

    • The sum of the two-digit W-complement is identical to that of the unsigned sum with the same bit-level representation

Three, the complement of non-

x=-2^ (w-1), -2^ (w-1)

x>-2^ (W-1), the-X

    • A bit-level representation of the complement:

For each one, then the result +1

Set K to the right of the 1 position, the K to the left of all the bits to take the reverse

Four, unsigned multiplication

Calculating the product model 2

Five, complement multiplication

Truncates the product of the 2w bit to w bit. That is, you need the power of the MoD 2 watts.

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

Six, multiplied by constant

Multiplication instructions are slow, while addition and displacement are relatively fast. So in the compiler, a combination of shift and addition operations is used instead of multiplying the constant factor

    • When the constant is 2, the K-Power is: Shift the K-bit directly to the left.
    • When a constant is not an integer power of 2, a constant c is represented as a sum of several integral powers of 2, combined with shift operations and addition operations.

Overflow does not affect the result.

Seven, the power of dividing by 2

Multiplication is slower than Fabienne. When the divisor is an integer power of 2, it is resolved by moving right

    • Unsigned number-Logical right Shift

The unsigned number is divided by the K power of 2, which is equivalent to moving the K-bit to its logical right.

    • Complement--Arithmetic right shift

Complement the arithmetic left shift, you need to consider the complement number of positive and negative, positive numbers rounded down to zero, negative numbers should be rounded up to zero. So here comes the bias before the shift, i.e.:

X≥0, the X-arithmetic right shifts the K-bit

x<0, first x Plus (2^k)-1, and then the arithmetic right shift K-bit

Viii. Summary

The "integer operation" performed by the computer is actually a modulo operation.

Whether the operands are expressed in unsigned or complementary form, there are exactly the same or very similar bit-level behavior.

§4 floating Point

A floating-point representation encodes a rational number of shapes such as V=x x (2^y) for very large numbers, numbers that are very close to 0, or as approximations to real operations

Pay less attention to accuracy, attention to speed and simplicity

One or two decimal

Represents a number as a shape such as x/(2^K): writes x as a binary and inserts a binary decimal point into the K position from the right

Second, IEEE floating point representation

1.IEEE floating point Standard:

Use v= ( -1) ^s*m*2^e 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-Power of Ε=1/2

2. Coding rules:

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)

3. 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.

4. Three Encoding cases

    • Normalized value

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.

(1) Order fields and order codes

Here is a signed integer in the form of a biased representation.

Order E = E-bias

bias=[2^ (K-1)-1]

(2) Small digits and mantissa

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)

    • Non-normalized values

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

(1) Order code

Order E = 1-bias

(2) Mantissa

Mantissa m = f(the value of the small number field, not containing the implied 1)

(3) Non-normalized function:

A. Provides a method for representing a value of 0.

B. Represents those very close to 0 of the number. Gradually overflow

    • s special value

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

(1) Infinity: Small number segments are all 0

(2) Nan is not a number

Small number field not 0

The result of some operations cannot be a real number or an infinite value when it is returned. or represents uninitialized data.

Third, rounding

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

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. ( four six in, five mating )

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 arithmetic

1. 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

Satisfying monotonicity under certain conditions

Floating-point numbers in the C language

    • Conversion of int, float, double

Int→float will not overflow but may be rounded

Int/float→double results retain exact values

Double→float may overflow to ±∞ and may be rounded due to small accuracy

The float/double→int rounds to 0 and can overflow.

Problems encountered:



1. Error in compiling the 28-page code in the book

Check the code seems to be nothing wrong, do not know why ... at last, I commented out the line . The source code is as follows

2. Exercise 2.52 do not understand, I hope the teacher can explain in class

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.