The relationship between number conversion and IP address

Preface

In life, we mentioned that numbers are all in decimal system, such as 1.2.3.4, etc., but they are not in computers. Computers use binary systems, that is, 0 and 1. The number system can be converted. Commonly used is binary decimal octal hexadecimal. Let’s talk about the calculation method in detail below.

The concept of number system

1 3 basic concepts

Number system: The method of counting refers to the method of expressing values ​​with a set of fixed symbols and uniform rules. For example, the method of carrying in the counting process is called the carry counting system. The carry counting system has three elements: digit, base, and weight.
Digit: Refers to the position of a number symbol in a number.
Base: Refers to the number of digital symbols that can be used on a digit in a certain carry counting system. For example, the base of a decimal number is 10, and the base of an octal number is the same as 8.
Bit weight: In a certain carry counting system, the size represented by the number, that is, the size of the value represented by a 1 in a certain bit.

2 Number system calculation

The so-called "binary", in short: every two enters one. For example, the number 123 is expressed in
binary calculation as follows . Conversion between binary and decimal:
decimal to binary, the method is: decimal number divided by 2 and remainder method, that is, decimal number divided by 2, the remainder is the number on the weight, and the result is The quotient value continues to divide by 2, and the calculation continues until the quotient is 0.
Binary to decimal, the method is: expand the binary numbers according to the weight, add to get the decimal number
. Conversion between binary and octal:
binary to octal, 3 binary numbers expand and add according to the weight to get 1 octal number. (Note that the conversion of 3 digits from binary to octal starts from right to left, and 0 is added when it is insufficient.) The
method for converting octal to binary is: divide an octal number by dividing by 2 to obtain a binary number, and each octal is 3 Binary, zeros will be added to the left when insufficient.
Conversion between binary and hexadecimal The
method of binary to hexadecimal conversion is similar to the method of binary to octal conversion. Octal is three in one, and hexadecimal is four in one. (Note that the conversion of 4 digits from binary to hexadecimal starts from right to left, and 0 is added when it is insufficient.) The
method of converting hexadecimal to binary is: hexadecimal number is divided by 2 and the remainder is obtained. Number, each hexadecimal is 4 binary, if it is insufficient, add zeros on the leftmost side.

Definition and function of IP address

The IP address is a 32-bit address assigned to each host connected to the Internet, which is composed of a host part and a network part.
The host part is used to determine the size of the terminal (how many can be accommodated at most), and the network part is used to determine whether the terminal is in the same network segment. For example, the computers in the same department of the company should be kept on the same network segment and the number of hosts should be within the range of the host part.
The IP address is a 32-digit binary number, expressed in dotted 4-segment decimal notation, and the unit is converted to 1 byte = 8 bits.
The IP address in use is ipv4, which is the fourth edition. Now that the ipv4 public network address has been exhausted, it is impossible to give a device an ip, and then it will transition to ipv6, which is a 128-bit binary
number.

The role of the subnet mask

It has two main functions: one is to shield part of the IP address, to distinguish between network identification and host identification, and to explain whether the IP address is on a local area network or a remote network; secondly, it divides a large IP network into several small sub-networks. The internet. Subnet mask can reduce IP waste. With the development of the Internet, more and more networks have emerged, some of which are hundreds, and some are just a few, which waste a lot of IP addresses. Therefore, it is necessary to divide subnets and use subnets to improve network applications. effectiveness. After the subnet mask is set successfully, the network address and host address are fixed. Like the IP address, the length of the subnet mask is 32 bits, and it can also be decimal.
The subnet mask can also be expressed in binary, where a continuous 1 represents the network part, and a continuous 0 represents the host part.

Classification of IP addresses

IP addresses are divided into 5 categories: ABCDE
IP addresses are classified according to network numbers and host numbers, and are divided into three categories: A, B, and C, and special addresses D and E. All 0s and all 1s are reserved.
Type A: (1.0.0.0-126.0.0.0) (default subnet mask: 255.0.0.0 or 0xFF000000) The first byte is the network number, and the last three bytes are the host number. The front of this type of IP address is "0", so the network number of the address is between 1 and 126. Generally used in large networks.
Type B: (128.0.0.0-191.255.0.0) (default subnet mask: 255.255.0.0 or 0xFFFF0000) The first two bytes are the network number, and the last two bytes are the host number. The front of this type of IP address is "10", so the network number of the address is between 128 and 191. Generally used in medium-scale networks.
Type C: (192.0.0.0-223.255.255.0) (subnet mask: 255.255.255.0 or 0xFFFFFF00) The first three bytes are the network number, and the last byte is the host number. The front of this type of IP address is "110", so the network number of the address is between 192 and 223. Generally used in small networks.
Class D: It is a multicast address. The front of this type of IP address is "1110", so the network number of the address is between 224 and 239. Generally used for multicast broadcast users
E: it is a reserved address. The front of this type of IP address is "1111", so the network number of the address is between 240 and 255, which is used for scientific research purposes.

Among the three main types of IP addresses, three areas are reserved as private addresses. The address ranges are as follows:
Class A address: 10.0.0.0~10.255.255.255
Class B address: 172.16.0.0~172.31.255.255
Class C address: 192.168.0.0~192.168.255.255
return address: 127.0.0.1. It is also the local address, which is equivalent to localhost or local IP. Generally used for testing. For example: ping 127.0.0.1 to test whether the local TCP/IP is normal.
Private addresses can only appear in the local area network and can be reused, because each local area network is an independent branch. If it is not connected to the external network, it will not affect the communication of other local area networks. The
public address appears on the Internet. If the address is repeated, it will Communication is not possible because the address must be unique.

Effective host capacity

Indicates how much host capacity can be accommodated in the IP, usually effective host capacity = 2m-2 (m is the number of digits of the host), pay special attention to the network identification and broadcast address can not be used for the preparation of the host's ip address)
c type effective Host capacity = 254
Class B effective host capacity = 65534
Class A effective host capacity = 16777214

Guess you like

Origin blog.csdn.net/weixin_49172531/article/details/111667490