A data reverse sequence conversion method, device, equipment and medium
By combining AND and OR operations, the problem of low efficiency in reverse byte data conversion under the low-bit-first encoding rule is solved, achieving fast and accurate reverse conversion processing and improving work efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- LAUNCH TECH CO LTD
- Filing Date
- 2022-10-13
- Publication Date
- 2026-06-05
AI Technical Summary
Under the low-bit-first encoding rule, existing technologies have low efficiency in reversing byte data, making it difficult to process large amounts of data quickly and accurately.
By acquiring the target byte data, setting the initial reverse byte data value, and using a combination of AND and OR operations, the reverse byte data is gradually updated until the preset number of times is met, thus achieving the reverse conversion of the byte data.
Quickly and accurately reverse-convert byte data, improving work efficiency and saving a lot of time.
Smart Images

Figure CN115525232B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and medium for data reverse order conversion. Background Technology
[0002] Computers store numerical values by combining basic units of information called bits, typically represented by 0 and 1. Since a single bit can only express a small amount of information, individual bits are usually linked together to form larger storage units. This smallest unit is called a byte, which consists of 8 bits and is sufficient to store a single char type of data.
[0003] In information communication, there is a phenomenon where the least significant bit (LSB) is sent first. The data received by the receiving end is stored according to the bits sent by the sending end; the receiving end receives the data exactly as the sending end sends it. If the sending end's current encoding rule is LSB-first, then the data received by the receiving end will be other data. When calculating the checksum of this data, the final checksum will be incorrect. Therefore, it is necessary to first swap the LSB and LSB of the received data to obtain the reversed data. Only then can the calculated checksum be correct.
[0004] Currently, when the encoding rule is low-order first, the byte data needs to be sorted and then reversed on the paper before the correct check value can be calculated. However, this method not only results in very low work efficiency, but also makes it difficult to process large amounts of byte data quickly and accurately.
[0005] In summary, how to quickly and accurately reverse byte data is a problem that needs to be solved. Summary of the Invention
[0006] In view of this, the purpose of this invention is to provide a data reversal conversion method, apparatus, device, and medium, capable of quickly and accurately performing reversal conversion on byte data. The specific solution is as follows:
[0007] Firstly, this application discloses a data reversal transformation method, including:
[0008] Get the target byte data sent by the data sender, and set the initial value of the reversed byte data to be obtained;
[0009] Perform a bitwise AND operation between the target byte data and 0x01 after shifting left by a first numerical bit to obtain a first operation result, and determine whether the first operation result is zero;
[0010] If it is not zero, then the reversed byte data is ORed with 0x01 after shifting left by the second numerical bit to obtain the second operation result, and the reversed byte data is updated using the second operation result;
[0011] The first value is increased by a preset unit value, and the second value is decreased by the preset unit value. Then, the process jumps back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by the first value, until a preset number of operations are satisfied, so as to obtain the updated reversed byte data.
[0012] Optionally, after determining whether the first operation result is zero, the method further includes:
[0013] If the result of the first operation is zero, then the first value is increased by a preset unit value, and the second value is decreased by the preset unit value, and then the process jumps back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by the first value.
[0014] Optionally, after obtaining the updated reversed byte data, the method further includes:
[0015] The reversed byte data is used to calculate a check value to obtain a data check value corresponding to the target byte data.
[0016] Optionally, before setting the initial value of the reversed byte data to be acquired, the method further includes:
[0017] Determine the data encoding rules used to send the target byte data;
[0018] If the data encoding rule is low-order first, then after the target byte data is obtained, the step of setting the initial value of the reverse byte data to be obtained is executed.
[0019] Optionally, after determining the data encoding rule for sending the target byte data, the method further includes:
[0020] If the data encoding rule is high-order bit first, then after obtaining the target byte data, the check value of the target byte data is calculated to obtain the corresponding data check value.
[0021] Optionally, the data reversal method further includes:
[0022] Set the preset unit value to 1.
[0023] Optionally, the data reversal method further includes:
[0024] The preset number of executions is set based on the total number of bits in the target byte data.
[0025] Secondly, this application discloses a data reversal conversion device, comprising:
[0026] The data acquisition module is used to acquire the target byte data sent by the data sender and set the initial value of the reverse byte data to be acquired.
[0027] The AND operation module is used to perform an AND operation on the target byte data and 0x01 after shifting left by a first numerical bit to obtain a first operation result, and to determine whether the first operation result is zero;
[0028] The OR operation module is used to perform an OR operation on the reversed byte data and 0x01 after left shifting by a second numerical bit if the result is not zero, so as to obtain a second operation result, and update the reversed byte data using the second operation result;
[0029] The reverse data acquisition module is used to add a preset unit value to the first value and decrease the preset unit value to the second value, and then jump back to the step of performing a bitwise AND operation between the target byte data and 0x01 after left shifting the first value, until a preset number of times is satisfied, so as to obtain the updated reverse byte data.
[0030] Thirdly, this application discloses an electronic device, including:
[0031] Memory, used to store computer programs;
[0032] A processor is configured to execute the computer program to implement the steps of the aforementioned disclosed data reversal method.
[0033] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed data reversal conversion method.
[0034] As can be seen, this application acquires the target byte data sent by the data sending end and sets the initial value of the reversed byte data to be acquired; performs a bitwise AND operation on the target byte data and 0x01 shifted left by a first numerical bit to obtain a first operation result, and determines whether the first operation result is zero; if it is not zero, performs an OR operation on the reversed byte data and 0x01 shifted left by a second numerical bit to obtain a second operation result, and updates the reversed byte data using the second operation result; increases the first value by a preset unit value, and decreases the second value by the preset unit value, and then jumps back to the step of performing a bitwise AND operation on the target byte data and 0x01 shifted left by a first numerical bit, until a preset number of times is satisfied to obtain the updated reversed byte data. Therefore, after obtaining the target byte data, this application needs to set the initial value of the reversed byte data to be obtained after reverse conversion. Then, it performs a bitwise AND operation on the target byte data and 0x01 shifted left by one numerical bit, and checks whether the first result of the AND operation is zero. If it is not zero, it performs a bitwise OR operation on the reversed byte data with the initial value and 0x01 shifted left by two numerical bits to obtain a second result, and uses the second result to update the reversed byte data. The first value is increased by a preset unit, and the second value is decreased by a preset unit, and the step of performing the bitwise AND operation on the target byte data and 0x01 shifted left by one numerical bit is repeated until the preset number of times is met, resulting in the final updated reversed byte data. This method enables fast and accurate reverse conversion of byte data sent by the data sender, improving work efficiency and saving a significant amount of time. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0036] Figure 1 This is a flowchart of a data reversal conversion method disclosed in this application;
[0037] Figure 2 This is a flowchart of a specific data reversal conversion method disclosed in this application;
[0038] Figure 3 This is a schematic diagram of a specific data reversal process disclosed in this application;
[0039] Figure 4 This is a schematic diagram of the structure of a data reversal conversion device disclosed in this application;
[0040] Figure 5 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0041] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0042] Currently, when the encoding rule is least significant bit first, the byte data needs to be sorted and then reversed on the manuscript paper before the correct check value can be calculated. However, this method not only results in very low work efficiency but also makes it difficult to process large amounts of byte data quickly and accurately. Therefore, this application discloses a data reversal conversion method, apparatus, device, and medium that can quickly and accurately perform byte data reversal conversion.
[0043] See Figure 1 As shown in the figure, this application discloses a data reversal conversion method, which includes:
[0044] Step S11: Obtain the target byte data sent by the data sender and set the initial value of the reverse byte data to be obtained.
[0045] In this embodiment, target byte data sent by the data sender is acquired. There can be multiple target byte data, and the target byte data is denoted as Ter. An initial value is set for each reversed byte data to be acquired, and the reversed byte data is denoted as Data. Specifically, the initial value can be set to 0, which in binary is Data = 0000 0000 = 0x00.
[0046] Step S12: Perform a bitwise AND operation between the target byte data and 0x01 after shifting left by the first numerical bit to obtain the first operation result, and determine whether the first operation result is zero.
[0047] In this embodiment, the target byte data is ANDed with 0x01 after shifting left by the first numerical bit to obtain the first operation result, and it is determined whether the first operation result is zero. It should be noted that the binary representation of 0x01 is 00000001, and the operation rule for AND is that if 0 is encountered, the result is 0. Here, the first numerical bit is denoted as i, and in the specific implementation, i starts from 0.
[0048] For example, if the target byte data is 0000 0011, then the first result of the AND operation with 0000 0001 (left-shifted by 0 bits) is 0000 0001, which means the first result is not zero; if the target byte data is 00000010, then the first result of the AND operation with 0000 0001 (left-shifted by 0 bits) is 0000 0000, which means the first result is zero.
[0049] Step S13: If it is not zero, perform an OR operation between the reversed byte data and 0x01 after shifting left by the second numerical bit to obtain the second operation result, and use the second operation result to update the reversed byte data.
[0050] In this embodiment, if the result of the first operation is not zero, the reversed byte data is ORed with 0x01 after shifting left by the second numerical bit to obtain the second operation result, and the reversed byte data is updated using the second operation result. It should be noted that the OR operation rule is that if it encounters 1, it returns 1. Here, the second numerical value is denoted as 7-i, where i starts from 0.
[0051] For example, if the current reversed byte data is Data = 0000 0000, and 0x01 is shifted left by 7 bits to get 01000000, then the result of the OR operation between 0000 0000 and 0100 0000 is 0100 0000. This result is then used to update the reversed byte data. After this update, the reversed byte data will be 0100 0000, i.e., Data = 0100 0000 = 0x40.
[0052] Step S14: Increase the first value by a preset unit value and decrease the second value by the preset unit value, then jump back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by the first value, until a preset number of operations are satisfied, so as to obtain the updated reversed byte data.
[0053] In this embodiment, a preset unit value is added to the first value and a preset unit value is decreased to the second value. Then, the process jumps back to the step of performing a bitwise AND operation between the target byte data and 0x01 after shifting the first value to the left. That is, if the current first value is 0 and the second value is 1, then in the second loop, the first value is 1 and the second value is 6, and so on, until the preset number of times is met, so as to obtain the final updated reversed byte data.
[0054] As can be seen, this application acquires the target byte data sent by the data sending end and sets the initial value of the reversed byte data to be acquired; performs a bitwise AND operation on the target byte data and 0x01 shifted left by a first numerical bit to obtain a first operation result, and determines whether the first operation result is zero; if it is not zero, performs an OR operation on the reversed byte data and 0x01 shifted left by a second numerical bit to obtain a second operation result, and updates the reversed byte data using the second operation result; increases the first value by a preset unit value, and decreases the second value by the preset unit value, and then jumps back to the step of performing a bitwise AND operation on the target byte data and 0x01 shifted left by a first numerical bit, until a preset number of times is satisfied to obtain the updated reversed byte data. Therefore, after obtaining the target byte data, this application needs to set the initial value of the reversed byte data to be obtained after reverse conversion. Then, it performs a bitwise AND operation on the target byte data and 0x01 shifted left by one numerical bit, and checks whether the first result of the AND operation is zero. If it is not zero, it performs a bitwise OR operation on the reversed byte data with the initial value and 0x01 shifted left by two numerical bits to obtain a second result, and uses the second result to update the reversed byte data. The first value is increased by a preset unit, and the second value is decreased by a preset unit, and the step of performing the bitwise AND operation on the target byte data and 0x01 shifted left by one numerical bit is repeated until the preset number of times is met, resulting in the final updated reversed byte data. This method enables fast and accurate reverse conversion of byte data sent by the data sender, improving work efficiency and saving a significant amount of time.
[0055] See Figure 2 As shown, this application discloses a specific data reversal method. Compared to the previous embodiment, this embodiment further explains and optimizes the technical solution. Specifically, it includes:
[0056] Step S21: Obtain the target byte data sent by the data sender and determine the data encoding rule used to send the target byte data. If the data encoding rule is low-order bit first, set the initial value of the reverse byte data to be obtained.
[0057] In this embodiment, it is necessary to determine the data encoding rule used to send the target byte data. If the data encoding rule is little-endian first, then the initial value of the reversed byte data to be acquired is set. That is, the target byte data only needs to be reversed when the data encoding rule is little-endian first.
[0058] In another specific implementation, after determining the data encoding rule for sending the target byte data, the method further includes: if the data encoding rule is high-order bit first, then after obtaining the target byte data, a checksum calculation is performed on the target byte data to obtain the corresponding data checksum. That is, if the data encoding rule is high-order bit first, the checksum calculation is performed directly on the target byte data to obtain the corresponding data checksum, without the need for reverse order processing.
[0059] Step S22: Perform a bitwise AND operation between the target byte data and 0x01 after shifting left by the first numerical bit to obtain the first operation result, and determine whether the first operation result is zero.
[0060] Step S23: If it is not zero, perform an OR operation between the reversed byte data and 0x01 after left shifting by the second numerical bit to obtain the second operation result, and use the second operation result to update the reversed byte data.
[0061] In one specific implementation, if the result of the first operation is not zero, the reversed byte data is ORed with 0x01 after shifting left by the second numerical bit, and the reversed byte data is updated using the result of the second operation obtained by the OR operation.
[0062] In another specific implementation, after determining whether the first operation result is zero, the method further includes: if the first operation result is zero, increasing the first value by a preset unit value and decreasing the second value by the preset unit value, and then jumping back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by a first value. That is, if the first operation result is zero, the reversed byte data obtained last time is still retained. For example, if the first operation result obtained by performing a bitwise AND operation between the target byte data and 0x01 shifted left by 0 bits is zero, then the preset unit value is directly increased to 0, the preset unit value is decreased to 7, and the method jumps back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by a first value, and the Data value at this time is still the initial value 0.
[0063] Step S24: Increment the first value by 1 and decrease the second value by 1, then jump back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by the first value, until a preset number of operations are satisfied to obtain the updated reversed byte data.
[0064] In this embodiment, the preset unit value is specifically 1, and i can specifically start from 0. So in the first loop, the first value is 0 and the second value is 7; in the second loop, the first value is 1 and the second value is 6; in the third loop, the first value is 2 and the second value is 5, and so on, until the preset number of times is met, the loop ends and the final reversed byte data is obtained.
[0065] Furthermore, the above method also includes setting the preset execution count based on the total number of bits in the target byte data. It can be understood that if the total number of bits in the target byte data is 8, then the preset execution count can be set to 8, meaning it needs to loop 8 times.
[0066] Step S25: Calculate the check value of the reversed byte data to obtain the data check value corresponding to the target byte data.
[0067] In this embodiment, the obtained reversed byte data is used to calculate the check value to obtain the data check value corresponding to the target byte data. That is, through the above scheme, when the data encoding rule is set to low bit first, the target byte data can be reversed to obtain the correct data check value.
[0068] For a more detailed description of the process of step S22, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0069] As can be seen, in this embodiment of the application, when the current data encoding rule is determined to be little-endian first, after obtaining the target byte data sent by the data sender, it is necessary to perform reverse order conversion to obtain its reversed byte data. Then, a check value is calculated on the reversed byte data to obtain the data check value corresponding to the target byte data. Through the eight loops in the above scheme, the byte data sent by the data sender can be reversed quickly and accurately, thereby improving work efficiency. If the data encoding rule is big-endian first, there is no need to perform reverse order conversion; the data check value can be calculated directly.
[0070] See Figure 3 As shown, the technical solution in this application will be described in detail below, taking the target byte data transmitted by the data sender as 0x3A, i.e., 00111010:
[0071] First, obtain the target byte data Ter = 0x3A = 0011 1010, and set the initial value of the reversed byte data Data = 0x00 = 0000 0000; the first value is denoted as i, and the second value is denoted as 7-i;
[0072] In the first loop, i = 0. Then, 0x3A is ANDed with 0x01 after shifting left by 0 bits to get the first result, i.e., 0x3A&(0x01<<0=0x01)=0x00. In other words, the first result is 0. Therefore, the Data value remains 0x00. Then, i = 0 is incremented by 1 to get i = 1.
[0073] In the second loop, i = 1. Then, the first result is obtained by performing a bitwise AND operation between 0x3A and 0x01 (shifted left by 1 bit), i.e., 0x3A & (0x01 << 1 = 0x02) = 0x02. The first result is not 0. Then, the second result is obtained by performing a bitwise OR operation between the reversed byte data Data = 0x00 and 0x01 (shifted left by 6 bits), i.e., Data | = (0x01 << (7-1)) = 0x40 = 0100 0000. Data has been updated to the second result after the bitwise OR operation. Then, i = 1 is incremented by 1 to get i = 2. 7 - i = 6 is decremented by 1 to get 7 - i = 5.
[0074] In the third loop, i = 2. Then, the AND operation between 0x3A and 0x01 (left-shifted by 2 bits) is performed to obtain the first result, i.e., 0x3A & (0x01 << 2 = 0x04) = 0x00. That is, the first result is 0. The Data value remains the result of the second loop, i.e., Data = 0x40 = 0100 0000. Then, i = 2 is incremented by 1 to get i = 3. 7 - i = 5 is decremented by 1 to get 7 - i = 4.
[0075] In the 4th loop, i = 3. Then, the first result is obtained by performing a bitwise AND operation between 0x3A and 0x01 (shifted 3 bits to the left): 0x3A & (0x01 << 3 = 0x08) = 0x08. The first result is not 0. The second result is obtained by performing a bitwise OR operation between the reversed byte data Data = 0x40 and 0x01 (shifted 4 bits to the left): Data | = (0x01 << (7-3)) = 0x50 = 0101 0000. Data has been updated to the second result after the bitwise OR operation. Then, 1 is added to i = 3 to get i = 4. 1 is subtracted from 7 - i = 4 to get 7 - i = 3.
[0076] In the 5th loop, i = 4. Then, the first result is obtained by performing a bitwise AND operation between 0x3A and 0x01 (shifted 4 bits to the left): 0x3A & (0x01 << 4 = 0x10) = 0x10. The first result is not 0. The second result is obtained by performing a bitwise OR operation between the reversed byte data Data = 0x50 and 0x01 (shifted 3 bits to the left): Data | = (0x01 << (7-4)) = 0x58 = 0101 1000. Data has been updated to the second result after the bitwise OR operation. Then, i = 4 is incremented by 1 to get i = 5. 7 - i = 3 is decremented by 1 to get 7 - i = 2.
[0077] In the 6th loop, i = 5. Then, the first result is obtained by performing a bitwise AND operation between 0x3A and 0x01 (shifted 5 bits to the left): 0x3A & (0x01 << 5 = 0x20) = 0x20. The first result is not 0. The second result is obtained by performing a bitwise OR operation between the reversed byte data Data = 0x58 and 0x01 (shifted 2 bits to the left): Data| = (0x01 << (7-5)) = 0x5C = 0101 1100. Data has been updated to the second result after the bitwise OR operation. Then, i = 5 is incremented by 1 to get i = 6, and 7 - i = 2 is decremented by 1 to get 7 - i = 1.
[0078] In the 7th loop, i = 6. Then, the AND operation between 0x3A and 0x01 (left-shifted by 6 bits) is performed to obtain the first result, i.e., 0x3A&(0x01<<6=0x40)=0x00, which means the first result is 0. The Data value remains the result of the 6th loop, i.e., Data=0x5C=0101 1100. Then, i=6 is incremented by 1 to get i=7. Then, 7-i=1 is decremented by 1 to get 7-i=0.
[0079] In the 8th loop, i = 7. Then, the first result is obtained by performing a bitwise AND operation between 0x3A and 0x01 (shifted 7 bits to the left): 0x3A & (0x01 << 7 = 0x80) = 0x00. This means that the first result is 0. Therefore, the Data value remains the result from the 6th loop: Data = 0x5C = 0101 1100.
[0080] Therefore, after 8 iterations, the reversed byte data Data = 0101 1100, corresponding to the target byte data Ter = 0011 1010, is obtained, thus achieving the reverse byte data conversion. Furthermore, the change in the Data value in each iteration shows that the value of the lower bits of Ter is synchronized starting from the high-order bits of Data.
[0081] See Figure 4As shown in the figure, this application discloses a data reversal conversion device, which includes:
[0082] The data acquisition module 11 is used to acquire the target byte data sent by the data sender and set the initial value of the reverse byte data to be acquired;
[0083] AND operation module 12 is used to perform an AND operation on the target byte data and 0x01 after shifting left by a first numerical bit to obtain a first operation result, and to determine whether the first operation result is zero;
[0084] OR operation module 13 is used to perform an OR operation on the reversed byte data and 0x01 after left shifting by a second numerical bit if the result is not zero, so as to obtain a second operation result, and update the reversed byte data using the second operation result;
[0085] The reverse data acquisition module 14 is used to add a preset unit value to the first value and decrease the preset unit value to the second value, and then jump back to the step of performing a bitwise AND operation between the target byte data and 0x01 after left shifting the first value, until a preset number of times is satisfied, so as to obtain the updated reverse byte data.
[0086] As can be seen, this application acquires the target byte data sent by the data sending end and sets the initial value of the reversed byte data to be acquired; performs a bitwise AND operation on the target byte data and 0x01 shifted left by a first numerical bit to obtain a first operation result, and determines whether the first operation result is zero; if it is not zero, performs an OR operation on the reversed byte data and 0x01 shifted left by a second numerical bit to obtain a second operation result, and updates the reversed byte data using the second operation result; increases the first value by a preset unit value, and decreases the second value by the preset unit value, and then jumps back to the step of performing a bitwise AND operation on the target byte data and 0x01 shifted left by a first numerical bit, until a preset number of times is satisfied to obtain the updated reversed byte data. Therefore, after obtaining the target byte data, this application needs to set the initial value of the reversed byte data to be obtained after reverse conversion. Then, it performs a bitwise AND operation on the target byte data and 0x01 shifted left by one numerical bit, and checks whether the first result of the AND operation is zero. If it is not zero, it performs a bitwise OR operation on the reversed byte data with the initial value and 0x01 shifted left by two numerical bits to obtain a second result, and uses the second result to update the reversed byte data. The first value is increased by a preset unit, and the second value is decreased by a preset unit, and the step of performing the bitwise AND operation on the target byte data and 0x01 shifted left by one numerical bit is repeated until the preset number of times is met, resulting in the final updated reversed byte data. This method enables fast and accurate reverse conversion of byte data sent by the data sender, improving work efficiency and saving a significant amount of time.
[0087] In some specific embodiments, after the AND operation module 12, the following may also be included:
[0088] The numerical processing unit is configured to, if the first operation result is zero, add a preset unit value to the first value and decrease the preset unit value to the second value, and then jump back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by the first value.
[0089] In some specific embodiments, after the reverse data acquisition module 14, the system may further include:
[0090] The check value calculation unit is used to calculate the check value of the reversed byte data to obtain the data check value corresponding to the target byte data.
[0091] In some specific embodiments, the data acquisition module 11 may further include:
[0092] An encoding rule determination unit is used to determine the data encoding rule for sending the target byte data;
[0093] The low-order byte determination unit is used to perform the step of setting the initial value of the reverse byte data to be acquired after acquiring the target byte data if the data encoding rule is low-order byte first.
[0094] In some specific embodiments, after the encoding rule determination unit, the system may further include:
[0095] The high-order priority determination unit is used to calculate the check value of the target byte data after obtaining the target byte data if the data encoding rule is high-order priority, so as to obtain the corresponding data check value.
[0096] In some specific embodiments, the data reversal device may further include:
[0097] A numerical setting unit is used to set the preset unit value to 1.
[0098] In some specific embodiments, the data reversal device may further include:
[0099] The execution count setting unit is used to set the preset execution count based on the total number of bits of the target byte data.
[0100] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the data reversal conversion method performed by the electronic device disclosed in any of the foregoing embodiments.
[0101] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0102] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0103] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored on it include operating system 221, computer program 222 and data 223, etc., and the storage method can be temporary storage or permanent storage.
[0104] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system 221 can be Windows, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the data reversal conversion method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the electronic device from external devices, as well as data collected by its own input / output interface 25.
[0105] Furthermore, embodiments of this application also disclose a computer-readable storage medium storing a computer program. When the computer program is loaded and executed by a processor, it implements the method steps performed during the data reversal process disclosed in any of the foregoing embodiments.
[0106] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0107] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0108] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0109] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0110] The above provides a detailed description of the data reversal conversion method, apparatus, device, and storage medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for reversing data order, characterized in that, include: Get the target byte data sent by the data sender, and set the initial value of the reversed byte data to be obtained; Perform a bitwise AND operation between the target byte data and 0x01 after shifting left by a first numerical bit to obtain a first operation result, and determine whether the first operation result is zero; If it is not zero, then the reversed byte data is ORed with 0x01 after shifting left by the second numerical bit to obtain the second operation result, and the reversed byte data is updated using the second operation result; The first value is increased by a preset unit value, and the second value is decreased by the preset unit value. Then, the process jumps back to the step of performing a bitwise AND operation between the target byte data and 0x01 after shifting left by the first value, until a preset number of operations are satisfied, so as to obtain the updated reversed byte data. Wherein, the total number of bits of the target byte data is 8, the initial value is 0x00, the first value is i, the second value is 7-i, the preset unit value is 1, the preset number of times is 8, the value range of i is 0 to 7, and i starts from 0.
2. The data reversal conversion method according to claim 1, characterized in that, After determining whether the result of the first operation is zero, the method further includes: If the result of the first operation is zero, then the first value is increased by a preset unit value, and the second value is decreased by the preset unit value, and then the process jumps back to the step of performing a bitwise AND operation between the target byte data and 0x01 shifted left by the first value.
3. The data reversal conversion method according to claim 1, characterized in that, After obtaining the updated reversed byte data, the process further includes: The reversed byte data is used to calculate a check value to obtain a data check value corresponding to the target byte data.
4. The data reversal conversion method according to claim 1, characterized in that, Before setting the initial value of the reversed byte data to be acquired, the method further includes: Determine the data encoding rules used to send the target byte data; If the data encoding rule is low-order first, then after the target byte data is obtained, the step of setting the initial value of the reverse byte data to be obtained is executed.
5. The data reversal conversion method according to claim 4, characterized in that, After determining the data encoding rules for sending the target byte data, the method further includes: If the data encoding rule is high-order bit first, then after obtaining the target byte data, the check value of the target byte data is calculated to obtain the corresponding data check value.
6. The data reversal conversion method according to claim 1, characterized in that, Also includes: Set the preset unit value to 1.
7. The data reversal conversion method according to any one of claims 1 to 6, characterized in that, Also includes: The preset number of times is set based on the total number of bits of the target byte data.
8. A data reversal conversion device, characterized in that, include: The data acquisition module is used to acquire the target byte data sent by the data sender and set the initial value of the reverse byte data to be acquired. The AND operation module is used to perform an AND operation on the target byte data and 0x01 after shifting left by a first numerical bit to obtain a first operation result, and to determine whether the first operation result is zero; The OR operation module is used to perform an OR operation on the reversed byte data and 0x01 after left shifting by a second numerical bit if the result is not zero, so as to obtain a second operation result, and update the reversed byte data using the second operation result; The reverse data acquisition module is used to add a preset unit value to the first value and decrease the preset unit value to the second value, and then jump back to the step of performing a bitwise AND operation between the target byte data and 0x01 after left shifting the first value, until a preset number of times is satisfied, so as to obtain the updated reverse byte data. Wherein, the total number of bits of the target byte data is 8, the initial value is 0x00, the first value is i, the second value is 7-i, the preset unit value is 1, the preset number of times is 8, the value range of i is 0 to 7, and i starts from 0.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the data reversal conversion method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the data reversal conversion method as described in any one of claims 1 to 7.