In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Talking about the common carry system of computer and network: binary (Binary), decimal (Decimal) and hex (Hexadecimal)
We are most familiar with binary, decimal and hexadecimal systems, from the mathematics we first came into contact with in preschool or kindergarten to the following ten numbers that we deal with almost every day in our daily life.
But then again, do you really understand these 10 numbers? Or do you understand decimal?
Today we will take decimal as the starting point and talk about binary, hexadecimal and the conversion between them. Before we talk about these binary systems, let's take a look at the concept of binary:
The so-called binary system is the carry system, which is a carry method prescribed by people. Carry / position counting is a way of counting, so it is also known as carry notation / digit counting, which can represent all values with limited numeric symbols. The number of numeric symbols that can be used is called cardinality or radix, and the cardinality is n, which is called n-carry system, or n-ary for short.
For any carry system-n system, it means that the number in a certain position is carried from right to left every "n". The decimal system is one for every "ten", the hexadecimal system is one for every sixteen, the "binary" system is one for every two, and so on, the n-ary is every n-carry. Now the most commonly used is the decimal system, usually using 10 Arabic numerals 0-9 for counting.
Note: the decimal system is 0-9 ten values for counting, not 1-10, and other decimal systems are the same for n-numbering using 0muri-(nMel 1) numbers instead of 0Mui n.
Count value: equal to multiplying the value of each cell above by the value of the cell instance and then adding the values of all the cells.
Take the value of the above example as an example: 1x million + 2X million + 3X million + 4X 100,000 + 5X million + 6X thousand + 7X white + 8X + 9X1=123456789.
The decimal system is very easy to understand, because we have been in contact with it since childhood, so we are very familiar with it. What happens if you suddenly switch to binary counting and use binary counting in your daily life? The answer is that you will almost go crazy, because binary is generally designed for computers to understand and use it, not for us to use it in daily life, because binary has only two values 0 and 1 to count. if a large number is expressed in binary, it will be a long number. For example, 11011011 this makes you look like a rune and can't say its value right away, but the computer is not, it prefers to read and use this "rune".
In fact, when learning the network, especially when dealing with IP addresses, you need to really understand binary and the conversion between binary and decimal, hexadecimal, which is very important. Let's start with binary, which is very simple. Binary uses only the numbers 0 and 1, where each value corresponds to one bit (binary bit). The binary bits are arranged in right-to-left order, and the bit value doubles each time you move one bit to the left. Usually we take every four or eight bits as a group, calling them nibble and Byte, respectively.
Count value: equal to multiplying the value of each cell above by the value of the real cell instance and then adding the values of all the cells.
Take the value of the above example as an example: 1X128 + 0X64 + 1X32 + 0X16 + 1X8 + 0X4 + 1X2 + 0X1 =
128 '032' 080 '080' 020 '0170
Conversion between binary and decimal
Decimal and binary have been introduced above, and here's how to convert them. The following table lists the half-byte and the decimal values represented by each byte.
The bit value of the bits in the half byte
The bit value of the bits in the byte
8 4 2 1
128 64 32 16 8 4 2 1
This means that if a bit has a value of 1, when calculating a half-byte or decimal value for a byte, its bit value should be added to all its bit values with a value of 1. If it is 0, it is not considered.
If each bit of the half byte is 1, 8, 4, 2, and 1 are added, and the result is the maximum value of 15-half byte. Assuming that the value of the half byte is 1010, that is, the corresponding bit values of 1 are 8 and 2, the corresponding decimal value is 8 / 2 / 10.
Similarly, a byte is converted in the same way as a half-byte, but the value of the byte is much larger than the maximum value of 15 of the half-byte. If each byte is 1, the value is as follows (the byte has 8 bits):
128 "64" 32 "16" 8 "4" 2 "1" 255.
The conversion from decimal to binary is the opposite of the above method, which is as follows:
1. First take a binary value that is closest to the decimal value and less than the decimal size.
two。 The difference is obtained by subtracting the proximity value from the decimal value.
3. Follow the first and second steps and then take the second, the third, and so on.
4. The difference is 0. 5%.
5. Perform an OR operation on the result of all the bit values, and the result of the operation is the corresponding binary value.
The following is illustrated by an example:
For example, decimal 234 is converted to binary.
The binary value closest to the size of and 234 is 224 (11100000).
234-224010
The nearest binary value to 10 is 8 (00001000)
10-8 / 2 (00000010)
Perform and operate on the above binaries:
11100000
00001000
00000100
11101100
Conversion between hexadecimal and binary and decimal
Hexadecimal is completely different from binary and decimal, we convert binary to hexadecimal by reading half-bytes. Why? Because a half byte satisfies exactly the maximum value of 15 in hexadecimal. That is, all bits of the half byte are taken as 1.
1111, with a decimal value of 8'4'2'1'15. The decimal system uses 0-9 ten digits, while what does the hexadecimal system use instead of six decimal digits? 10, 11, 12, 13, 14, 15? That won't work, because the six numbers 10-15 are not double digits, so we use A, B, C, D, E, F to represent 10, 11, 12, 13, 14, 15.
Each hexadecimal character is equivalent to a half-byte, while two hexadecimal characters are equivalent to one byte. To calculate the binary value for the hexadecimal number, you can convert the two hexadecimal characters to binary halves, and then merge them into one byte. The conversion method between hexadecimal and binary and decimal is introduced with several examples:
Example 1, hexadecimal 0x7B (usually the 0x prefix represents the following hexadecimal) is converted to binary and decimal.
Convert to binary:
As mentioned above, each character in hexadecimal is half a byte, so let's take a look at it separately: 7: 0111 and byte 1011, so the whole byte is 01111011.
Convert to decimal system:
7 X (16) 1 + B X (16) 0 = 112 + 11 = 123.
Example 2, binary 10110101 is converted to hexadecimal and decimal.
Convert to hexadecimal:
First split 10110101 bytes into two bytes: 1011 and 0101. The hexadecimal character for 1011 is B (8-0-2-1), and the hexadecimal character for 0101 is 5 (0-4-0-0-1), so the value of hexadecimal is 0xB5.
Convert to decimal:
128 + 32 + 16 + 4 + 1 = 181
In fact, for any number, we can use different carry systems to express it. For example, the decimal number 57 (10) can be expressed as 00111001 (2) in binary, 212 (5) in pentadecimal, or 71 (8) in octal and 39 (16) in hexadecimal. The values they represent are all the same, but we are used to using decimal in our daily life and computers often use binary and hexadecimal to express it.
Well, this is the end of this article. I hope to give friends who have just come into contact with the computer or network field a good start!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.