1.1 Walk into 0 and 1

  • 8-bit circuit, the leftmost one represents positive and negative, 0 represents positive number, 1 represents negative number, the maximum 0111 1111, that is 127; The value ranges from -128 to 127
  • The original code, inverse code and complement of positive numbers are consistent;
  • 1. A digit with a sign bit of 1 and a numeric bit corresponding to a positive number; Inverse code: in addition to the symbol bit corresponding to the original code inverse; Complement: inverse +1
  • Binary integers eventually appear as complement.
  • Need to pay attention toThe complement of -128 is specified as 1000 0000,No reverse code, source code; Here’s what I think I need to feelOverflow, overflow, overflowHere is an article on the -128 complement problem; Can go underwww.cnblogs.com/flowerslip/…
For example: (35) + (-35) = 0010 0011 + 1101 11101 = 10000 0000 = 0000 0000 = 0Copy the code
  • 1 bit, that is, 1 bit, abbreviated B; Eight bits make up a Byte, or a Byte, short for B
  • Displacement operation, in the left shift << and right shift >> two operations (Signed bit displacement operation), the sign bit participates in the movement,We divide negative numbers and we move to the rightIn practice, << 1 is equivalent to *2, while >> 1 is similar to dividing by 2 (low level is omitted).
  • >>>The unsigned bit moves to the right (note that there is no case of <<< left shift). When moving to the right, positive and negative high positions fill 0, and the minimum value of positive number moving to the right continuously is 0. Negative numbers keep moving to the right at a minimum of 1;
  • In practical programming, the displacement operation only works on integer (32-bit) and long integer (64-bit) numbers. The number of bits moved by the integer type is a result of mod 32, i.e. 35 >> 1 is the same result as 35 >> 33
  • bitwiseOr ` ` (|), are 0, 0; bitwiseIf both and (&) are 1, it is 1; bitwiseXor (^), same is 0, different is 1; bitwiseI take the inverse (~), I take the inverse.
true ^ true = false
Copy the code

* logic and (&), logic, or (| |) has function of short circuit

1.2 floating point number

The computer defines two kinds of decimals, fixed point and floating point

1.2.1 Scientific notation

  • A times 10 to the n can also be represented as aen, 1 <= |a| < 10

1.2.2 Floating point representation

  • The sign bit
  • Exponent bits
  • Mantissa bits

1.2.3 Addition and subtraction operations

  • Zero detection
  • For order operation
  • Mantissa sum
  • Outcome planning

1.2.4 Floating point Usage

Double precision is recommended when using floating-point numbers; The use of integer storage is recommended for services requiring absolute accuracy, such as the use of minutes in RMB. When storing decimals in the database, the use of decimal is recommended, and the use of float and double is prohibited

1.3 Character Sets and Garbled Characters

  • ASCII: 26 upper and lower case letters, 10 digits, and special characters, more than 64(2^6), requires 7 groups of consecutive signal identification, parity check with a bit (1bit), so 8 bits basically meet the English character input, that is ASCII;
  • GB2312: ONE byte (8bit,1bit used) can identify 128 characters. A large number of Chinese characters, compatible with ASCII, using 2 bytes, including 6763 commonly used Chinese characters;
  • GBK: Support traditional, compatible with GBK2312.
  • Unicode: a unique encoding for characters in each language to meet the needs of cross-language communication. There are three encoding methods and implementation methods: UTF-8, UTF-16, and UTF-32
  • Utf-8: Encoding of Unicode variable-length characters in bytes. It compresses Unicode characters in 1 to 6 bytes and represents the most commonly used characters in fewer bytes
  • GBKEncoding, a Chinese character accounted forTwo bytes, an English character accounted forA byte.
  • UTF-8Encoding is variable length encoding, usually Chinese characters occupyThree bytesThe Chinese characters after the extension of the B area account for four bytes and one English characterA byte;

1.5 the TCP/IP

1.5.1 Network Protocols

TCP/IP in Chinese is transmission control Protocol/Internet Protocol, this big family also has HTTP, HTTPS, FTP, SMTP, UDP, ARP, PPP, IEEE802.x and so on

  • TCP layered framework

  • The link layer: Defines a data frame, in bytes, that writes the physical addresses, data, and parity bits of the source and destination machines.

The MAC address is 6 characters in length and contains 48 bits. Run the ifconfig-a command to view the MAC address, for example, F4 :5c:89: AE: BD :23 and F4 :5c:89. The first 24 bits are assigned by the management organization and the last 24 bits are assigned by the manufacturer to ensure that the NIC is unique in the world

  • The network layer: Defines network addresses based on IP addresses and divides network segments. MAC addresses are addressed using THE ADDRESS resolution Protocol (ARP) within subnets, and packets are routed and forwarded outside subnets, namely, IP packets
  • Transport layer: After the packet is sent to the target computer through the network layer, the identity is confirmed and the data is given to the application program to achieve port-to-port communication. Protocol UDP TCP.

UDP only add port and other parts of information on IP packets, for no connection, unreliable, used for video communication, teleconference (less a frame just as well); TCP is a connection-oriented and reliable data transmission method established through the end-to-end retransmission mechanism

  • The application layerWhen the uncle of the transport layer arrives at the application, he interprets the data in some uniform protocol format; The SMTP protocol

Summarize the data sending process: package the established protocol (application layer) -> add the ports of both sides (transport layer) -> add the IP addresses of both sides (network layer) -> (link layer) add the MAC addresses of both sides, and check the data into data frames, which pass through multiple routers and gateways and reach the target machine. “Port — IP address — MAC address” encapsulates and sends back data, and vice versa

1.5.2 IP

IP is connectionless and stateless, with no additional mechanism to ensure that packets sent arrive in an orderly manner.

  • The protocol structure is relatively simple, focusing on the TTL of the packet, which is the maximum number of routers the packet can pass through. After the initial TTL value is set by the source host, the TTL value decreases each time the packet passes through a router during transmission. When this value is set, the packet is discarded and an ICMP notification packet is sent

Source host to prevent the source host from sending packets endlessly

1.5.3 ESTABLISHING a TCP Connection

TCP: Transmission control protocol. It is connection-oriented and ensures reliable data transmission from end to end. Ensure reliable transmission:

Each byte is numbered to verify the validity of each packet, timeout retransmission, sliding Windows and congestion control mechanisms to deal with network problems

TCP: FLAG is set to 1, indicating that this parameter is valid

  • SYN: Used as a synchronization signal for establishing a connection
  • ACK: Used for receiving dataTo confirm, confirmed dataConfirm serial numbersaid
  • FIN: Indicates that no data needs to be sent, indicating that the established connection needs to be closed

Three-way handshake

  • A sends A packet and sets SYN to 1. The serial number of the packet is X
  • After receiving the packet from A, USER B sends A packet to receive the request through SYN and sets the SYN and ACK values to 1. The sequence number of the received packet is Y. The sequence number of the received packet must be X +1, indicating that A’s SYN is received
  • After receiving the corresponding packet from B, A needs to set ACK to 1 and sequence number to Y +1

The main purpose of the three-way handshake: message reciprocity and prevention of timeout dirty connections (there is no third handshake, the server just waits)

1.5.4 TCP Disconnection

TCP is full-duplex communication. Both parties can send and receive dataCopy the code

Four times to wave

  • User A wants to close the connection and sends A FIN signal to user B
  • User B responds to the ACK and tells user A that the connection is ok, but it needs to wait for user B to finish processing data before sending A A FIN signal. At this time, A is in the semi-closed state (FIN_WAIT_2), and no new data can be sent
  • After making preparations for closing the connection, user B sends the FIN to user A, and user B also enters the semi-closed state.
  • After sending an ACK for the FIN of user B, user A enters the time-wait state. If user A does not receive any packet from user B after 2MSL(Maximum Segment Lifetime), user B determines that the last ACK sent by user A has been released

1.5.5 connection pool

We use connections to interact with systems; Connection number creation is limited by the number of FDS (file descriptors) on the server operating system. Creating more active connections consumes more FD’s. By default, a single process can have 1024 FD’s at the same time, and this value can be adjusted accordingly.

1.6 Information Security

1.6.1 Hackers and Security

The Information security system of Internet enterprises complies with the PRINCIPLES of CIA, namely Confidentiality, Intergrity and Availability.

1.6.2 SQL injection

The prevention of

(1) Filter special characters; (2) forbid string concatenation and strictly use parameter binding to pass IN SQL parameters; (3) Rationally use database access framework to prevent injection mechanism

1.6.3 XSS and CSRF

XSS cross-site scripting attack defense: filters or escapes user input data. CSRF cross-site request forgery defense: (1) CSRF Token authentication, using the same origin restriction of the browser. (2) Human-machine interaction, verifying short messages

1.6.5 HTTPS

  • DES is a symmetric encryption algorithm

  • SSL Is a secure socket protocol that operates between the transport layer and the application layer

  • HTTPS is HTTP over SSL. The ENCRYPTION capability of SSL is enhanced over HTTP transmission

  • RSA divides passwords into public and private keys, and because the two secret keys are not the same, it is called asymmetric encryption