Acquisition and data conversion method of common data type specified bit data

By encapsulating data conversion classes and function overloading features in C++, efficient acquisition, assembly and conversion of bit data in the display and control system of military payload equipment is achieved, solving the problem of cumbersome operations in traditional solutions and improving development efficiency and system performance.

CN120631379AActive Publication Date: 2025-09-12SICHUAN WEIBANG XINCHUANG TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202511120495.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-12
Publication Date
2025-09-12
Estimated Expiration
2045-08-12

AI Technical Summary

Technical Problem

In display and control systems such as military payload equipment, parsing and assembling bit data is cumbersome and requires high development complexity. Traditional solutions also lack a unified interface design, resulting in low development efficiency and increased system complexity.

Method used

The C++ encapsulation data conversion class and function overloading features are used to encapsulate the functions of obtaining specified bit data and assembling and converting data of different bits, and realize automatic data acquisition and assembly through right shift and bitwise AND operations.

Benefits of technology

It significantly improves development efficiency, reduces repetitive coding work, improves data transmission efficiency and system stability, reduces manual coding error rate, and improves system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120631379A_ABST
    Figure CN120631379A_ABST
Patent Text Reader

Abstract

The invention discloses a common data type specified bit data acquisition and data conversion method, and relates to the technical field of data processing. According to the method, data conversion classes based on C + + are packaged, bit data acquisition and assembly conversion of common data types (such as char, short, int and float) are realized by using function heavy load characteristics, and a unified interface is provided to simplify a development process. According to the method, bandwidth occupation can be remarkably reduced (8 KB / s in a traditional scheme is reduced to 1 KB / s), coding time consumption is reduced (30 minutes are reduced to 5 minutes), code redundancy is reduced, the method is suitable for scenes such as equipment state monitoring and switch instruction transmission, and system performance and development efficiency are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data processing technology, and in particular, relates to a method for acquiring and converting specified bit data of a common data type. Background Art

[0002] In display and control systems for military payloads and other equipment, device status feedback and control command transmission are core functions. Since device status information and control commands are typically represented using binary data—for example, 0 and 1 represent the normal and faulty states of a device, or the on and off states of a control command, respectively—to conserve communication bandwidth, multiple states or commands often need to be compressed and represented using multiple bits within a single byte. This bit-based manipulation requirement is very common in real-world applications, but it also introduces significant development complexity and technical challenges. Traditional solutions often rely on manually implemented bit manipulation code to parse and assemble bit data, which is inefficient and error-prone. For example, to obtain specific bit data, developers need to write separate parsing logic for each data type (such as char, short, int, etc.). Furthermore, when assembling the bit data, they also need to set the state of each bit individually, resulting in lengthy and difficult-to-maintain code. Furthermore, traditional solutions lack a unified interface design, preventing the reuse of processing methods for different data types, further increasing development delays and workload.

[0003] From a performance perspective, traditional solutions also have significant deficiencies in transmission efficiency. For example, when monitoring the status of eight devices in real time, if each status is transmitted separately, 8 bytes of bandwidth are required, while after bit compression, only 1 byte is required to complete the same data transmission task. However, traditional methods usually require more than 30 minutes of coding time and generate 30 to 40 lines of code when implementing this compression, which not only reduces development efficiency but also increases the complexity of system integration. At the same time, the existing technology lacks mature class libraries or tools to simplify the parsing and conversion operations of bit data, forcing developers to repeatedly encapsulate similar functional modules, wasting a lot of time and resources. Summary of the Invention

[0004] The purpose of the present invention is to provide a method for obtaining and converting specified bit data of common data types, mainly to solve the problem of cumbersome operations of parsing and assembling bit data in display and control systems such as military payload equipment in the prior art.

[0005] To achieve the above object, the technical solution adopted by the present invention is as follows: A method for obtaining and converting specified bit data of a common data type includes the following steps: S1, using C++ encapsulation and function overloading features, encapsulates a data conversion class, which has the functions of obtaining specified bit data and assembling and converting different bit data; S2, the function of obtaining the specified bit data is implemented by calling the function of obtaining the specified bit data in the overloaded function; the function of obtaining the specified bit data is implemented by right shifting the source data and performing a bitwise AND operation; S3, the different bit data assembly conversion function is realized by calling the different bit data assembly conversion function in the overloaded function; the different bit data assembly conversion function completes the conversion of the target data by looping through the bit data in the array and combining bitwise OR and bitwise AND operations.

[0006] Furthermore, in the present invention, the method of calling the function to obtain the specified bit data is as follows: Define the variable to return the received data and specify the bit variable; Call the corresponding overloaded function according to the source data type; the source data is the data that the system receives from the device feedback and needs to be parsed.

[0007] Furthermore, in the present invention, the specific process of obtaining the designated bit data in step S2 is as follows: S21, a function for obtaining designated bit data receives the incoming source data and the designated bit position; S22, right-shift the source data according to the specified bit position, and perform a bitwise AND operation with 1 after the right shift is completed; S23, constructing a temporary variable to store the converted value and obtain the specified bit data.

[0008] Furthermore, in the present invention, the method of calling the different bit data assembly conversion function in the overloaded function is as follows: Build command storage array; Store the conversion instructions in the command storage array in sequence; Construct variables to store the returned data and array length after conversion; Call the corresponding overloaded function according to the parameter type of the data to be converted.

[0009] Furthermore, in the present invention, the specific process of assembling and converting the data of different bits in step S3 is as follows: S31, the different bit data assembly conversion function obtains the data return reference variable, the instruction array variable to be converted, and the array length variable; S32, determine whether the length of the array passed in is consistent with the bit length of the target conversion data type; if the lengths are inconsistent, return directly; if the lengths are consistent, proceed to step S33; S33, constructing a temporary data storage variable that has the same length as the target conversion data type; S34, looping through the data in the command storage array, determining whether the data in the command storage array is equal to 1, if it is equal to 1, setting the corresponding subscript bit data to 1, i.e., left shift operation, and performing a bitwise OR assignment operation on the left-shifted data and the temporary data storage variable; if it is not 1, setting the corresponding subscript bit data to 0, i.e., left shift operation, bitwise inverting the left-shifted data, and then performing a bitwise AND assignment operation on the inverted data and the temporary data storage variable; S35, after the traversal is completed, the data stored in the temporary data storage variable is assigned and returned to the data reference variable, that is, the converted data composed of multiple instructions is obtained.

[0010] Furthermore, in the present invention, the data types supported by the function for obtaining the specified bit data include char, short, int, and float types.

[0011] Compared with the prior art, the present invention has the following beneficial effects: (1) This invention automates the process of acquiring (right shift + bitwise AND) and assembling (loop traversal + bitwise operation) specified bits by encapsulating data conversion classes and function overloading in C++, eliminating the need for developers to manually implement the underlying bit manipulation logic. For example, it supports unified interface calls for multiple data types such as char, short, int, and float, reducing repetitive coding work and shortening the time required for single-function development from 30 minutes in traditional solutions to 5 minutes, significantly improving development efficiency.

[0012] (2) This invention achieves compatibility with multiple data types through function overloading, eliminating the need to design separate parsing logic for each data type. Furthermore, the encapsulated class structure modularizes the code. Subsequent modifications or functional expansions (such as adding support for new data types) require only adjustments to the overloaded functions, without the need to restructure the overall logic. For example, when adding support for the double type, only the corresponding overloaded function needs to be added, reducing maintenance costs.

[0013] (3) The present invention reduces communication bandwidth usage through bit compression transmission (e.g., eight device states are reduced from 8 bytes to 1 byte). During assembly conversion, the array length is verified against the bit length of the target data type (step S32), avoiding invalid data processing and improving system stability. In practical applications, data transmission efficiency is increased by 8 times, and automated bit manipulation reduces manual coding errors, increasing data parsing accuracy from approximately 90% in traditional solutions to 99.9%. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 Schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0015] The present invention will be further described below with reference to the accompanying drawings and examples. The embodiments of the present invention include but are not limited to the following examples.

[0016] like Figure 1 As shown, the present invention encapsulates a C++-based data conversion class and combines the function overloading feature to achieve the acquisition of specified bit data of common data types and the assembly and conversion functions of different bit data.

[0017] The overall design process begins with defining a data conversion class object. This object serves as the core implementation of all bit operations, encapsulating multiple overloaded functions to support different types of data processing needs. Next, depending on the specific application scenario, functions are called to retrieve data at a specific bit or to assemble and convert data from different bits to complete the data parsing or assembly operations. The resulting data is then used for subsequent business logic processing or communication transmission.

[0018] In practical applications, source data variables typically originate from status information or control commands fed back by a device. This data is stored in bytes, with each bit representing a state or command. To extract the value of a specific bit, a specific bit index variable must be passed in. For example, in a military payload display and control system, when parsing eight status messages fed back by a device, the Get Specified Bit Data function can be called to extract the value of each bit one by one. This process operates as follows: First, the source data and a specific bit index are received as input parameters. The source data is then right-shifted by the bit number corresponding to the index, shifting the target bit to the least significant bit. Next, the result of the right shift is bitwise ANDed with the value 1 to extract the value of the target bit. The resulting value is returned as 0 or 1, indicating a normal or abnormal state, respectively. This operation not only works with char data but can also be extended to other common data types such as short, int, and float through function overloading to meet diverse needs. The parsed bit values ​​are then transmitted to the display and control system's human-machine interface. When the bit value is 1, the corresponding device's status alarm indicator is triggered; when the bit value is 0, the normal state indicator remains displayed.

[0019] For the assembly conversion operation of different bit data, the target data reference variable is used to store the converted result. In this process, the bit storage array and array length variable need to be provided. The assembly conversion function of different bit data first checks whether the array length is consistent with the bit length of the target data type. If the length does not match, an error prompt is returned directly; otherwise, the temporary variable tempData is initialized to 0, and each data in the command storage array is traversed in a loop. For elements with a value of 1, it is left-shifted by the number of bits corresponding to the subscript and then bitwise ORed with tempData; for elements with a value of 0, the left-shifted value is inverted and bitwise ANDed with tempData. After the above steps, the target data finally generated will be assigned to the target data reference variable to complete the assembly conversion of the bit data.

[0020] In order to more clearly illustrate the actual operation process of the present invention, it is described in detail below with reference to specific examples. Suppose a certain type of load display and control system needs to monitor the status information of 8 key components in real time. In the state initialization stage, the operating status of these devices is represented as a one-dimensional array of char type, where the array element value 0 indicates that the device is normal, and the value 1 indicates that the device is faulty. In this embodiment, devices No. 2, 5, and 8 are in a faulty state, and the remaining devices are operating normally. Therefore, the initialization array is [0, 1, 0, 0, 1, 0, 0, 1]. After entering the data compression and conversion stage, the above-mentioned state array is compressed into a single byte data in bit order by calling the arrayToDataType function in the different bit data assembly conversion function. The specific implementation process is: traverse each element of the array in turn, and when the element value is 1, set the bit position of the corresponding sequence number in the target byte to 1; when the element value is 0, set the corresponding bit position to 0. The final generated compressed byte value is binary 01001001, corresponding to hexadecimal 0x49. This compressed byte is then sent to the remote monitoring center via a serial communication interface, significantly saving transmission bandwidth compared to the traditional 8-byte transmission scheme where each state is transmitted separately.

[0021] On the receiving end, the decompression process similarly involves the getDesignateBitData function within the different bit-position data assembly conversion functions, which extracts each bit's value from the compressed byte. For the i-th device state, the compressed byte is right-shifted i bits and then bitwise ANDed with the value 1 to obtain the value of that bit. The parsed bit values ​​are then transmitted to the display and control system's human-machine interface. When the bit value is 1, the corresponding device's status alarm indicator is triggered; when the bit value is 0, the normal status display remains. This process not only achieves efficient data parsing but also improves system visualization. The resulting bandwidth savings are shown in Table 1.

[0022] Table 1 Bandwidth saving data Another typical application scenario is switch command assembly. Suppose a load display and control system needs to simultaneously control eight relay switches, where 0 represents off and 1 represents on. During the human-computer interaction input phase, after the user selects the state of each switch through the graphical user interface, the generated Boolean array is passed to the arrayToDataType function. This function compresses the Boolean array into a single-byte control instruction using the aforementioned method. For example, if the user chooses to turn on switches 1, 3, and 7, the generated Boolean array is [1, 0, 1, 0, 0, 0, 1, 0]. After compression, the generated control instruction is 10000101 in binary, corresponding to 0x85 in hexadecimal. This compressed instruction is then sent to the controlled device via the serial communication interface, completing the batch update operation.

[0023] To further verify the technical effect of the present invention, the differences in coding time and number of lines of code between the traditional solution and this solution are compared. In the traditional solution of manual bit operation, developers need to write independent code logic for each data type separately. For example, for the bit acquisition operation of char type data, it is necessary to write boundary checking and core operation code, totaling about 30-40 lines of code, which takes about 30 minutes. In this solution, through encapsulation and function overloading features, only 7-10 lines of code need to be written to achieve the same function, which takes about 5 minutes. This significant efficiency improvement not only reduces the developer's workload, but also reduces the risk of errors introduced by manual coding.

[0024] In summary, the present invention provides an efficient and concise method for acquiring and converting bit data through encapsulation and function overloading features. This method solves the problem of tedious parsing and assembling bit data in the prior art, and significantly improves development efficiency and system performance. In display and control systems such as military payload equipment, the present invention has important application value and can meet the requirements of scenarios with high efficiency and low bandwidth requirements. Through unified interface design and automated processing, the present invention not only simplifies the development process, but also improves the overall performance of the system, providing strong support for technological innovation in related fields.

[0025] The above embodiment is only one of the preferred implementation methods of the present invention and should not be used to limit the scope of protection of the present invention. Any changes or modifications that have no substantive meaning made to the main design concept and spirit of the present invention, as long as the technical problems solved are still consistent with the present invention, should be included in the scope of protection of the present invention.

Claims

1. A method for obtaining and converting data of specified bits of common data types, characterized in that: The following steps are involved: S1, using C++ encapsulation and function overloading features, encapsulates a data conversion class, which has the functions of obtaining specified bit data and assembling and converting different bit data; S2, the function of obtaining the specified bit data is implemented by calling the function of obtaining the specified bit data in the overloaded function; the function of obtaining the specified bit data is implemented by right shifting the source data and performing a bitwise AND operation; S3, the different bit data assembly conversion function is realized by calling the different bit data assembly conversion function in the overloaded function; the different bit data assembly conversion function completes the conversion of the target data by looping through the bit data in the array and combining bitwise OR and bitwise AND operations.

2. The method for obtaining and converting specified bit data of a common data type according to claim 1, characterized in that: The method of calling the function to obtain the specified bit data is as follows: Define the variable to return the received data and specify the bit variable; Call the corresponding overloaded function according to the source data type; the source data is the data that the system receives from the device feedback and needs to be parsed.

3. The method for obtaining and converting specified bit data of a common data type according to claim 2, characterized in that: The specific process of obtaining the specified bit data in step S2 is as follows: S21, a function for obtaining designated bit data receives the incoming source data and the designated bit position; S22, right-shift the source data according to the specified bit position, and perform a bitwise AND operation with 1 after the right shift is completed; S23, constructing a temporary variable to store the converted value and obtain the specified bit data.

4. The method for acquiring and converting specified bit data of a common data type according to claim 1, characterized in that: The method of calling the different bit data assembly conversion function in the overloaded function is as follows: Build command storage array; Store the conversion instructions in the command storage array in sequence; Construct variables to store the returned data and array length after conversion; Call the corresponding overloaded function according to the parameter type of the data to be converted.

5. The method for acquiring and converting specified bit data of a common data type according to claim 4, characterized in that: The specific process of assembling and converting different bit data in step S3 is as follows: S31, the different bit data assembly conversion function obtains the data return reference variable, the instruction array variable to be converted, and the array length variable; S32, determining whether the length of the array passed in is consistent with the bit length of the target conversion data type; If the lengths are inconsistent, return directly; If the lengths are the same, proceed to step S33; S33, constructing a temporary data storage variable with the same length as the target conversion data type; S34, looping through the data in the command storage array, determining whether the data in the command storage array is equal to 1, if it is equal to 1, setting the corresponding subscript bit data to 1, i.e., left shift operation, and performing a bitwise OR assignment operation on the left-shifted data and the temporary data storage variable; if it is not 1, setting the corresponding subscript bit data to 0, i.e., left shift operation, bitwise inverting the left-shifted data, and then performing a bitwise AND assignment operation on the inverted data and the temporary data storage variable; S35, after the traversal is completed, the data stored in the temporary data storage variable is assigned and returned to the data reference variable, that is, the converted data composed of multiple instructions is obtained.

6. The method for obtaining and converting specified bit data of a common data type according to claim 3, characterized in that: The data types supported by the function for obtaining specified bit data include char, short, int, and float types.

Citation Information

Patent Citations

  • A parallel solution method and system for pattern development

    CN109542406A

  • Data processing method and device, equipment, storage medium and program product

    CN114490853A

  • Attribute editing processing method and device using serialization, equipment and medium

    CN116450112A

  • Semi-homomorphic encryption fixed base number pre-calculation optimization method and system

    CN117118588A

  • Video encoding device, video decoding device, video encoding method and video decoding method

    WO2014049982A1