Method for acquiring and converting data of a common data type specifying bit data
By encapsulating data conversion classes and function overloading features in C++, efficient acquisition and assembly conversion of bit data in the display and control system of military payload equipment is achieved, solving the tedious parsing and assembly problems in traditional solutions and improving development efficiency and system performance.
Patent Information
- Application Number
- CN202511120495.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-12
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-08-12
AI Technical Summary
In display and control systems such as military payload equipment, parsing and assembling bit data is cumbersome and complex to develop. Traditional solutions lack a unified interface design, resulting in low development efficiency and prone to errors, as well as insufficient utilization of communication bandwidth.
The data conversion class is encapsulated in C++ and the function overloading feature is utilized to realize the automatic acquisition and assembly conversion of specified bit data, support unified interface calls for multiple data types, and realize efficient processing of bit data through right shift, bitwise AND operation and loop traversal.
It significantly improves development efficiency, reduces coding time and error rate, improves data transmission efficiency, reduces communication bandwidth usage, and significantly improves system stability and visualization effects.
Smart Images

Figure CN120631379B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of data processing, and in particular relates to a method for acquiring and converting data of specified bit positions of common data types. BACKGROUND
[0002] In a display and control system such as a military payload device, the transmission of device state feedback and control commands is one of the core functions. Since the state information of the device and the control command are usually represented by binary data, for example, 0 and 1 represent the normal and fault states of the device or the off and on states of the control command, in order to save communication bandwidth, multiple states or commands often need to be represented by multiple bit positions of a single byte. This bit-based operation requirement is very common in practical applications, but it also brings high development complexity and technical challenges. In the traditional scheme, the parsing and assembling of bit data usually relies on manually implemented bit operation code, which is not only inefficient but also prone to errors. For example, when acquiring specified bit position data, the developer needs to write independent parsing logic for each data type (such as char, short, int, etc.), and when assembling bit position data, the state of each bit position also needs to be set one by one, resulting in long and difficult-to-maintain code. In addition, the traditional scheme lacks a unified interface design, making it impossible to reuse the processing methods of different data types, further increasing the development time and workload.
[0003] From the performance point of view, the traditional scheme also has obvious deficiencies in transmission efficiency. For example, when monitoring 8 device states in real time, if each state is transmitted separately, it will occupy 8 bytes of bandwidth, while after bit compression, only 1 byte is needed to complete the same data transmission task. However, the traditional method usually takes more than 30 minutes to implement this compression, and generates 30 to 40 lines of code, which not only reduces the 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
[0004] The purpose of the present application is to provide a method for acquiring and converting data of specified bit positions of common data types, which mainly solves the problem of cumbersome bit data parsing and assembling operations in the existing technology in the display and control system of military payload devices.
[0005] To achieve the above purpose, the technical solution adopted by the present application is as follows:
[0006] A method for acquiring and converting data of specified bit positions of common data types, comprising the following steps:
[0007] S1, encapsulating a data conversion class with C++ encapsulation and function overloading features, the data conversion class having a specified bit data acquisition function and different bit data assembly conversion functions;
[0008] S2, the specified bit data acquisition function is implemented by calling the specified bit data acquisition function in the overloaded function; the specified bit data acquisition function is implemented by right shift operation and bitwise AND operation on the source data;
[0009] S3, the different bit data assembly conversion function is implemented by calling the different bit data assembly conversion function in the overloaded function; the different bit data assembly conversion function is implemented by traversing the bit data in the array and combining the bitwise OR and bitwise AND operations to complete the conversion of the target data.
[0010] Further, in the present application, the method of calling the specified bit data acquisition function is as follows:
[0011] Define a receiving data return variable and a specified bit variable;
[0012] Call the corresponding overloaded function according to the source data type; wherein the source data is the data received by the system from the device feedback which needs to be parsed.
[0013] Further, in the present application, the specific process of acquiring the specified bit data of step S2 is as follows:
[0014] S21, the specified bit data acquisition function receives the source data and the specified bit position passed in;
[0015] S22, right shift the source data according to the specified bit position, and perform bitwise AND operation with 1 after right shift;
[0016] S23, construct a temporary variable to store the converted value, and obtain the specified bit data.
[0017] Further, in the present application, the method of calling the different bit data assembly conversion function in the overloaded function is as follows:
[0018] Construct a command storage array;
[0019] Store the conversion instructions in the command storage array in order;
[0020] Construct a storage conversion return data variable and an array length variable;
[0021] According to the parameter type of the input data to be converted, call the corresponding overloaded function.
[0022] Further, in the present application, the specific process of different bit data assembly conversion in step S3 is as follows:
[0023] S31, the different bit data assembly conversion function obtains data return reference variable, instruction array variable needing conversion, array length variable;
[0024] S32, judge whether the length of the array passed in is consistent with the bit length of the target conversion data type; if the length is inconsistent, return directly; if the length is consistent, go to step S33;
[0025] S33, a temporary data storage variable consistent with the length of the target conversion data type is constructed;
[0026] S34, loop through the data in the command storage array, judge whether the data in the command storage array is equal to 1, if it is equal to 1, set the corresponding subscript bit data to 1, that is, left shift operation, and perform bitwise or assignment operation between the left shifted data and the temporary data storage variable; if it is not 1, set the corresponding subscript bit data to 0, that is, left shift operation, and perform bitwise not operation on the left shifted data, and perform bitwise and assignment operation between the inverted data and the temporary data storage variable;
[0027] S35, after the traversal, the data stored in the temporary data storage variable is assigned to the data reference variable, that is, the converted data composed of multiple instructions is obtained.
[0028] Further, in the present application, the data types supported by the specified bit data obtaining function include char, short, int, float type.
[0029] Compared with the prior art, the present application has the following beneficial effects:
[0030] (1) The present application automatically realizes the specified bit obtaining (right shift + bitwise and) and assembling (looping + bitwise operation) process through C++ encapsulation of data conversion class and function overloading, without the need for developers to manually implement the underlying bit operation logic. For example, the unified interface call of multiple types of data such as char, short, int, float, etc. reduces the repeated coding work, shortens the single-function development time from 30 minutes of the traditional scheme to 5 minutes, and significantly improves the development efficiency.
[0031] (2) The present application realizes multi-data type compatibility through function overloading feature, avoiding designing parsing logic for each data type. At the same time, the encapsulated class structure modularizes the code, and subsequent modification or extension of functions (such as adding support for new data types) only needs to adjust the overloaded functions, without the need to reconstruct the overall logic. For example, when double type support is added, only the corresponding overloaded function needs to be added, reducing maintenance costs.
[0032] (3) The application reduces the communication bandwidth occupation by bit compression transmission (such as reducing 8 bytes to 1 byte for 8 device states); and the array length and the target data type bit length are checked (step S32) during assembly conversion, so as to avoid invalid data processing and improve system stability. In actual application, the data transmission efficiency is improved by 8 times, and the manual coding error is reduced through automatic bit operation, so that the data analysis accuracy is improved from about 90% of the traditional scheme to 99.9%. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 The flowchart of the method of the application is shown. DETAILED DESCRIPTION
[0034] The application will be further described below in combination with the drawings and examples. The modes of the application include but are not limited to the following examples.
[0035] As shown in the drawings, the application realizes the acquisition of specified bit data of common data types and the assembly conversion of different bit data by packaging a C++-based data conversion class and combining the function overload feature. Figure 1
[0036] In the overall design process, the data conversion class object needs to be defined first. The object is the core carrier for implementing all bit operations, and multiple overloaded functions are encapsulated in the object to support different types of data processing requirements. Then, the specified bit data acquisition function or the different bit data assembly conversion function is called according to the specific application scenario, and the data parsing or assembly operation is completed. The final returned result data will be used for subsequent business logic processing or communication transmission.
[0037] In practical applications, source data variables are usually derived from device feedback status information or control commands. These data are stored in bytes, with each bit representing a state or instruction. To extract the value of a specific bit, the specified bit index variable is passed in. For example, in a military payload display control system, when 8 status information from a device needs to be parsed, the value of each bit can be extracted one by one by calling the specified bit data acquisition function. The specific operation principle of this process is as follows: first, the source data and the specified bit index are received as input parameters, then the source data is right shifted by the number of bits corresponding to the index, so that the target bit moves 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 final returned value is 0 or 1, representing normal or abnormal state respectively. This operation is not only applicable to char type data, but also extended to other commonly used data types such as short, int and float through function overloading, meeting the diversified needs. The parsed bit values are transmitted to the display control system human-machine interface, and when the bit value is 1, the corresponding device state alarm indicator is triggered; when the bit value is 0, the normal state display is maintained.
[0038] For assembly conversion operations 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 different bit data assembly conversion function first checks whether the array length is consistent with the bit length of the target data type. If the lengths do 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 looped through. For elements with a value of 1, left shift the corresponding index number of bits and perform a bitwise OR operation with tempData; for elements with a value of 0, take the inverse of the left shifted value and perform a bitwise AND operation with tempData. After the above steps, the final generated target data will be assigned to the target data reference variable, completing the assembly conversion of bit data.
[0039] In order to more clearly illustrate the actual operation process of the present application, the following is described in detail in combination with specific examples. Assume that a certain type of load display control system needs to monitor the state information of 8 key components in real time. In the state initialization stage, the running state of these devices is represented as a one-dimensional array of char type, where the array element takes value 0 to represent normal device and value 1 to represent device failure. In this embodiment, the 2nd, 5th and 8th devices are in a fault state, and the remaining devices are running normally. Therefore, the initialization array is [0, 1, 0, 0, 1, 0, 0, 1]. After entering the data compression conversion stage, the above 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: traversing the elements of the array in turn, when the element value is 1, the corresponding bit position in the target byte is 1; when the element value is 0, the corresponding bit position is 0. The final compressed byte value is binary 01001001, corresponding to hexadecimal 0x49. This compressed byte is then sent to the remote monitoring center through the serial communication interface, compared with the traditional 8-byte transmission scheme of each state transmission alone, the transmission bandwidth is significantly saved.
[0040] In the receiving end, the decompression process is also obtained from the compressed byte by the getDesignateBitData function in the different bit data assembly conversion function. For the state of the ith device, the compressed byte is right shifted by i bits and then bitwise ANDed with the value 1 to obtain the value of the bit. Subsequently, the parsed bit values are transmitted to the human-machine interface of the display control system. When the bit value is 1, the state alarm indicator of the corresponding device is triggered; when the bit value is 0, the normal state display is maintained. This process not only realizes efficient data analysis, but also improves the visualization effect of the system. The bandwidth saving data is shown in Table 1.
[0041] Table 1 Bandwidth saving data
[0042]
[0043] Another typical application scenario is switch instruction assembly. Assuming that a certain type of payload display control system needs to control 8 relays, where 0 represents off and 1 represents on. In the human-computer interaction input stage, 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 according to the method described above. For example, if the user selects to turn on the 1st, 3rd, and 7th switches, the generated Boolean array is [1, 0, 1, 0, 0, 0, 1, 0], and the compressed control instruction is binary 10000101, corresponding to hexadecimal 0x85. This compressed instruction is then sent to the controlled device through the serial communication interface, completing the batch update operation.
[0044] To further verify the technical effects of the present application, the differences in encoding time and code lines between the traditional scheme and the present scheme are compared. In the traditional scheme of manual bit operation, the developer needs to write independent code logic for each data type. For example, for the bit operation of char type data, about 30-40 lines of code are needed for boundary checking and core operation code, which takes about 30 minutes. In the present scheme, through encapsulation and function overloading features, only 7-10 lines of code are needed to achieve the same function, which takes about 5 minutes. This significant efficiency improvement not only reduces the workload of the developer, but also reduces the risk of errors introduced by manual coding.
[0045] In summary, the present application provides an efficient and concise bit data acquisition and conversion method through encapsulation and function overloading features. This method solves the problem of tedious bit data parsing and assembly in the prior art, significantly improving development efficiency and system performance. In military payload devices and other display control systems, the present application has important application value and can meet the requirements of high efficiency and low bandwidth scenarios. Through unified interface design and automatic processing, the present application not only simplifies the development process, but also improves the overall performance of the system, providing strong support for technical innovation in related fields.
[0046] The above embodiment is only one of the preferred embodiments of the present application and should not be used to limit the protection scope of the present application. Any modification or polishing without substantial meaning made within the main design idea and spirit of the present application, which still solves the same technical problem as the present application, should be included in the protection scope of the present application.
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 implemented 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; wherein, 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; According to the parameter type of the data to be converted, the corresponding overloaded function is called; The specific process of assembling and converting data of different bits 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.
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 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
Data processing method and device, equipment, storage medium and program product
CN114490853A
Attribute editing processing method and device using serialization, equipment and medium
CN116450112A