Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is android data check and what is the commonly used check algorithm

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "android data verification and commonly used verification algorithm is what", in daily operation, I believe many people in android data verification and commonly used verification algorithm is what the problem is there are doubts, small make up consult all kinds of information, sort out simple and easy to use operation method, hope to answer "android data verification and commonly used verification algorithm is what" doubts helpful! Next, please follow the small series to learn together!

1. Data verification process

Due to the influence of data transmission distance, unpredictable errors often occur in the communication data between computers and controlled equipment. In order to prevent these errors, data check methods are generally used in communication, and parity check and cyclic redundancy check are the most commonly used check algorithms.

Serial data in the transmission process, due to interference may cause information errors, there is "error code." We call how to find errors in transmission "code detection"; how to correct errors after discovery, called "error detection." Before, there have been hints that in order to ensure that the data will not go wrong during transmission, check bytes are generally added after each data packet.

The check process is a process jointly completed by the transmitting end (TX end) and the receiving end (RX end). As shown in the above figure, firstly, TX end calculates TX check byte according to check algorithm according to user layer protocol (data packet format), and places TX check byte in designated position of data packet according to protocol.

After receiving the data packet, the RX end takes out TX check bytes at designated positions, and calculates RX check bytes from the received data in a specified manner. If RX check bytes are equal to the received TX check bytes, it indicates that the data packet is valid, otherwise, the data packet should be abandoned.

2. Simple and rude parity check

The simplest and crudest method is "parity check," which transmits an odd/even parity bit in addition to each bit of the transmitted character. There are odd and even parity check strategies.

2.1 odd parity

In all the transmitted digits (including the number of characters and check bits), the number of "1" is odd, such as 1 0110,0101;0 0110,0001.

2.2 even parity

In all transmitted digits (including each digit and check digit of the character), the number of "1" is even, such as 1 0100,0101;0 0100,0001.

Parity check can detect some erroneous data in the process of information transmission (one-bit error code can be detected, and two-bit and more error codes cannot be detected). Parity check has a disadvantage, that is, it can only find errors, but can not correct errors; once found errors, then there is no way, can only repeat.

But parity is still widely used because it is so simple to use. However, there are still some good methods to correct error data, and have automatic error detection capabilities, such as cyclic redundancy code (CRC) detection.

3. XOR check

XOR check method is also very simple, and very common, although there is still the possibility of error after using this method, but because the XOR algorithm is very simple, programming effortless, general beginners use this method.

The NMEA-0183 wireless communication protocol introduced earlier is improved on the basis of XOR algorithm. Being able to understand XOR operations and use good XOR checking algorithms makes data processing programming easy.

4. Checksums

checksum, in data processing and data communications, used to verify the sum of a set of data items at a destination. It is usually expressed in hexadecimal notation. If the checksum value exceeds FF in hexadecimal, it is 255. It requires its complement as a checksum. It is usually used to ensure the integrity and accuracy of data in communications, especially long-distance communications.

These data items may be numbers or other strings of characters that are treated as numbers in the calculation of the test. Checksum refers to the accumulation of the number of bits transmitted, and at the end of the transmission, the receiver can determine whether all the data has been received according to this value. If the numbers match, the transfer is complete.

5. CRC cyclic redundancy code check

Cyclic Redundancy Check (CRC) is an error detection method based on division and remainder.

Recommended article: CRC check is so simple

In practical application, the transmitting device calculates a CRC value and sends the CRC value to the receiving device RX along with the data, the RX recalculates CR for the received data and compares the CR value with the received CRC value, and if the two CRC values are different, it indicates that an error occurs in data communication, and the data packet should be discarded.

In long-distance data communication, in order to ensure efficient and error-free transmission of data, it is necessary to check the data, and CRC is a very efficient error control method to check a transmitted data block. Currently, mainstream CRC can be divided into the following standards: CRC-12 code;CRC-16 code;CRC-CCITT code;CRC-32 code.

CRC-12 codes are usually used to transmit 6-bit character strings. CRC-16 and CRC-CCITT codes are used to transmit 8-bit characters, with CRC-16 being used in the United States and CRC-CCITT being used in European countries. CRC-32 codes are of limited use.

CRC is ubiquitous in the field of data storage and data communication: CRC/CCITT is adopted by FCS (Frame Error Detection Sequence) of well-known communication protocol X. 25, CRC32 is adopted by compression tool software such as ARJ/LHA, Japanese CRC16 is adopted by disk drive reading and writing, and CRC is also adopted as error detection means by image storage format GIF/TIFF.

5.1 CRC-16 is produced.

CRC-16 code consists of two bytes, each bit of CRC register is preset to 1 at the beginning, then the CRC register is XORed with 8-bit data, and then the CRC register is shifted from high to low, zero is added at the most significant bit (MSB) position, and the least significant bit (LSB, CRC register has been removed after shift) If it is 1, the register is XORed with predefined polynomial code, otherwise if LSB is zero, no XORed is required.

Repeat the above shift from high to low 8 times, the first 8-bit data is processed, and the CRC register value at this time is exclusive OR with the next 8-bit data and 8 shifts like the previous 8-bit data are performed. After all characters are processed, the CRC register value is the final CRC value.

The CRC calculation process is as follows:

(1)Set CRC register and assign FFFF(hex) to it;

(2)XOR the first 8-bit character of the data with the lower 8 bits of the 16-bit CRC register and store the result in the CRC register;

(3)CRC register shifts one bit to the right, MSB fills zero, shifts out and checks LSB;

(4)if LSB is 0, repeat that third step; if LSB is 1, CRC registe is OR different from polynomial code;

(5)Repeat steps 3 and 4 until all 8 shifts are complete. At this point, an 8-bit data is processed;

(6)Repeat steps 2 to 5 until all data are processed;

(7)The contents of the final CRC register are the CRC values.

5.2 How to understand CRC code?

CRC check is a polynomial division: the data packet to be sent as a large binary number, divided by a fixed binary number, the remainder is the CRC check code obtained.

At this point, the study of "android data verification and what is the commonly used verification algorithm" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report