Representation and processing of information
First, GCC compilation
When using the C99 feature, the GCC-STD=C99 XXX.C Lab building environment is 64 bits, compiled to 32-bit machine code: Gcc-m32 xxx.c
Second, the textbook guide
Three types of numbers:
unsigned (unsigned) encoding is based on the traditional binary notation, which represents a number greater than or equal to zero.
The complement (s-complement) encoding is the most common way to represent signed integers, which are numbers that can be positive or negative.
The floating-point (? oating-point) encoding is a two-base version of the scientific notation for real numbers.
Information security students from the reverse angle to consider why a loophole?
Overflow is generated.
Overflow: The representation of a computer is to encode a number with a limited number of bits, so that when the result is too large it causes some operations to overflow.
Integers and floating-point numbers have different mathematical properties because there are different ways to handle numbers that are limited:
Integer: Encodes a relatively small range of values, but with high accuracy
Floating-point number: Encodes a larger range of numbers, but this representation is near
Storage of information:
hexadecimal, binary, decimal conversion: learned.
Word: The computer has a word size, which indicates the nominal size of the integer and pointer data (nominal size). Because the virtual address is encoded in one of these words, the most important system parameter that the word length determines is the maximum size of the virtual address space. That is, for a machine with a word length of W, the virtual address range is 0~2w-1 and the program accesses up to 2w bytes. Computers are now more than 32 and 64 bits.
The gcc-m32 can generate 32-bit code on 64-bit machines, such as the lab building's environment.
Addressing and byte order
stored in the order from the highest valid byte to the lowest valid byte. The previous rule-the least significant byte in the front-most way, called the Small-end method. the big-endian method is the opposite.
Byte order is the basis of network programming, remember that the small end is "high-to-high, low-to-low", the big-endian opposite it can be.
using typedef Named data types
typedef declarations in the C language provide a way to name the data type.
Creation and indirect referencing of pointers
C's "Fetch address" operator & Create a pointer. In these three rows, the expression &x creates a pointer to the position where the variable x is saved. The type of the pointer depends on the type of x, so the three pointers are of the type int*, float*, and void**, respectively. (Data type void* is a special type of pointer that has no associated type information.) )
Boolean algebra
With or not, take the inverse operation. Bit operations. & and Doors: 0 is zero. | or door: one is one. ^ XOR Gate: The same is zero, the difference is one.
C bit-level operations in the language
The best way to determine the result of a bit-level expression is to extend the hexadecimal parameter to binary representation and perform a binary operation, and then convert back to hexadecimal
Mask : A position of one, indicating that the signal i is valid, 0 is the signal i is blocked.
A common use of bit-level arithmetic is to implement a mask operation, where the mask is a bit pattern that represents a collection of bits selected from a single word. Let's look at an example where the mask 0xFF (the lowest 8 bits is 1) represents the low byte of a word. Bit-level operations X&0xff generate a value that consists of the lowest valid byte of x, while the other bytes are set to 0. For example, for x=0x89abcdef, its expression will be 0x000000ef. The expression ~0 will generate a full 1 mask, regardless of the machine's word size. Although for a 32-bit machine, the same mask can be written as 0xFFFFFFFF, but such code is not portable.
C logical operations in the language
The C language also provides a set of logical operators | |, && and! , which correspond to the or, and and not operations in propositional logic, respectively.
C shift operations in the language
The C language also provides a set of shift operations to move the bit pattern to the left or right. For unsigned data (that is, integer objects declared with qualifier unsigned), the right shift must be logical. For signed data (the default declared integer object), the right shift of arithmetic or logic is possible.
Operator precedence issues related to shift operations
Often someone writes such an expression 1<<2+3<<4, which is intended to be (1<<2) + (3<<4). In C, however, the preceding expression is equivalent to 1<< (2+3) <<4, which is due to the higher precedence of addition (and subtraction) than the shift operation. Then, according to the binding rule from left to right, the parentheses should be 1<< (2+3) <<4, so the result is 512 instead of the expected 52.
Complement code
The use of complement can unify the mathematical operation into addition, as long as an adder can achieve all the mathematical operations.
There are two standard ways to represent signed numbers:
Anti-code (Ones ' complement): In addition to the most significant bit of the right is-(2w-1-1) and not -2w-1, it is the same as the complement.
Original Code (sign-magnitude):
The most significant bit is the sign bit, which is used to determine whether the remaining bits should take negative or positive weights.
C signed and unsigned numbers in a language
There are some peculiar behaviors in C language for this kind of processing, which contains both signed and unsigned number expressions. When an operation is performed, if one of its operands is signed and the other is unsigned, the C language implicitly converts the signed parameter coercion type to an unsigned number and assumes that the two numbers are nonnegative to perform this operation. As we are going to see, this method is not much different for standard arithmetic operations.
. IEEE floating point representation 1. Represents a number in the form of V = ( -1) s * M * 2E:
Symbol: s Determines whether the number is negative (s = 1) or positive (s = 0), while the symbolic bit interpretation for the value 0 is handled as a special case.
Mantissa: M is a binary decimal that has a range of 1 to 2-ε, or 0 to 1-ε.
Order code: The role of E is weighted to the floating point data, which is 2 of the power of the E (possibly negative).
2. Divide the bit representation of a floating-point number into three fields and encode the values:
A separate sign bit s directly encodes the symbol S.
The Order field of K-bit exp = EK-1...E1E0 encoded Order E.
The N-bit decimal segment Frac = fn-1...f1f0 encodes the mantissa m, but the encoded value also depends on whether the value of the Order field equals 0.
3. Two common format C languages in single-precision floating-point format float and double-precision floating-point format double.
In float, the S, exp, and Frac fields are 1 bits, k = 8 bits, and n = 23 bits respectively, resulting in a 32-bit representation;
In a double, the S, exp, and Frac fields are 1 bits, k = 11 bits, and n = 52 bits, respectively, and a 64-bit representation is obtained.
Problems in Learning:
(1) about overflow:
Due to the inherent flaw of C/D + + language, neither checking the array boundary nor checking type reliability, and the program developed in C + + language because the target code is very close to the machine core, so it can directly access the memory and register, as long as the reasonable encoding Applications are inherently more efficient than other high-level languages. However, the possibility of a memory overflow problem is also much greater in C + + language.
Improved method: detects overflow at output.
Information Security system Design Fundamentals third Week study summary