Computer network: calculate network number based on IP and subnet mask

The title feels wrong, but the idea of ​​solving the problem is correct.
It is known that the subnet mask of a class B address is 255.255.0.0, assuming that a class B address is 127.24.36.55, then its network number is: ()

A、127.24.0.0
B、0.0.36.55
C、255.255.36.55
D、127.24.36.55

Problem-solving idea:
convert the ip and subnet mask into binary numbers respectively, and then perform the "logical AND" operation, and convert the binary numbers obtained from the operation into decimal numbers.

ip: 127.24.36.55: 01111111.00011000.00100100.00110111
subnet mask: 255.255.0.0: 11111111.11111111.00000000.00000000
and operation: : 01111111.000 11000.00000000.00000000
converted to decimal: 127.24.0.0

Observation:
Since the binary number of 255 is all 1, and the binary number of 0 is all 0, after the logical AND operation, if there is 255
in the decimal subnet mask and ip , the area network number is the original number. If the decimal subnet If there is 0 in the mask and ip , then the local area network number is 0


Algorithm for choosing the topic
IP address: 10.0.10.63
Subnet mask: 255.255.255.224
Because we know that the first three digits of the network number must be 10.0.10, so we only need to calculate the last digit.
1. First subtract the last digit of the subnet mask from 256:
256 - 224 = 32
2. Calculate: the number not greater than the last digit of the IP address is 63, but is a multiple of 32.
This number is 32.
3. Then the network The last digit of the number is 32, and the network number is: 10.0.10.32


And operation (&): All True is True,
all 1 is 1, and 0 is 0.
0&0 is 0, 0&1 is 0, 1&0 is 0, 1&1 is 1

Or operation (|): True is True,
all 0 is 0, and 1 is 1.
0|0 is 0, 0|1 is 1, 1|0 is 1, 1|1 is 1

And, or operation thinking: 0Flase, 1True. And: 1True only if both are True; or: 1True if both are True.

Exclusive OR operation (^): True when different, that is, 1
is the same as 0, and 1 is different.
0^0 is 0, 0^1 is 1, 1^0 is 1, 1^1 is 0


How to convert decimal IP address to binary IP address
Decimal: 172.16.25.3
Binary: 10101100.00010000.00011001.00000011

8 is 0 times 2 to 7 times 2, 128 is 7 times 2

172
1 0 1 0 1 1 0 0
128 64 32 16 8 4 2 1

To convert binary to decimal, just add up the positions that are 1


Distinguish between the position of the network number and the host number in the ip address

The number of 1s in front of the subnet mask is the number of digits in the network number of the IP address! !

IP address: 10.0.10.63
Subnet mask: 255.255.255.224

IP address: 00001010.00000000.00001010.001|11111 #The first 27 digits are the network number, followed by the host number
Subnet mask: 11111111.11111111.11111111.111|00000

The number 27 means that the number of digits of the network number is 27, which means that the first 27 digits of the subnet mask are all 1, and the latter is 0.
insert image description here


Network address classification
A 0 start
B 128 start
C 192 start
D 224 start
E 240 start
insert image description here

Class A address subnet mask: 255.0.0.0
Class B address subnet mask: 255.255.0.0
Class C address subnet mask: 255.255.255.0

Reference:
https://blog.csdn.net/qq_20495901/article/details/123043729
https://blog.csdn.net/qq_20495901/article/details/123042165?spm=1001.2014.3001.5502
https://blog.csdn. net/qq_47188967/article/details/124830369

Guess you like

Origin blog.csdn.net/m0_37690430/article/details/127685098