CN117492702B - Conversion method of data streams at large end and small end - Google Patents

Conversion method of data streams at large end and small end Download PDF

Info

Publication number
CN117492702B
CN117492702B CN202311846152.9A CN202311846152A CN117492702B CN 117492702 B CN117492702 B CN 117492702B CN 202311846152 A CN202311846152 A CN 202311846152A CN 117492702 B CN117492702 B CN 117492702B
Authority
CN
China
Prior art keywords
data
binary data
byte
bit width
converting
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311846152.9A
Other languages
Chinese (zh)
Other versions
CN117492702A (en
Inventor
刘国东
胥执辉
杨敏
胥学辰
尹富君
丁建明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Kaidi Feiyan Technology Co ltd
Original Assignee
Chengdu Kaidi Feiyan Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu Kaidi Feiyan Technology Co ltd filed Critical Chengdu Kaidi Feiyan Technology Co ltd
Priority to CN202311846152.9A priority Critical patent/CN117492702B/en
Publication of CN117492702A publication Critical patent/CN117492702A/en
Application granted granted Critical
Publication of CN117492702B publication Critical patent/CN117492702B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a conversion method of data streams at large and small ends, and belongs to the technical field of computer software. A conversion method of large and small end data streams comprises a large end data stream coding step and a small end data stream coding step; the large end data stream encoding step comprises the following steps: reading a section of binary data from a first byte buffer zone, and converting the section of binary data into unsigned integers to obtain a first data section; converting the first data segment into binary data with a first preset bit width, and storing the binary data with the first preset bit width into a second byte buffer area according to the sequence of the big end mode. The invention provides a universal conversion method of data streams at the large end and the small end, which greatly reduces the work of developers, improves the development efficiency and shortens the development time.

Description

Conversion method of data streams at large end and small end
Technical Field
The invention belongs to the technical field of computer software, and particularly relates to a conversion method of a large-end data stream and a small-end data stream.
Background
Size-end data conversion is an important concept and technology in the field of computers, and relates to the memory arrangement sequence of multi-byte data. Traditional approaches to compute size-end endian by mostly manually computing the encoding of the size-end, or by simple shifting, may be effective in some specific situations, but have significant drawbacks in terms of versatility and flexibility.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a conversion method of a data stream at a size end.
The aim of the invention is realized by the following technical scheme: a conversion method of large and small end data streams comprises a large end data stream coding step and a small end data stream coding step;
the large end data stream encoding step comprises the following steps:
reading a section of binary data from a first byte buffer zone, and converting the section of binary data into unsigned integers to obtain a first data section;
converting the first data segment into binary data with a first preset bit width, and storing the binary data with the first preset bit width into a second byte buffer area according to the sequence of the big end mode;
the step of encoding the small-end data stream comprises the following steps:
reading a section of binary data from the third byte buffer zone, and converting the section of binary data into unsigned integers to obtain a third data section;
and converting the third data segment into binary data with a third preset bit width, and storing the binary data with the third preset bit width into a fourth byte buffer area according to the sequence of the small end mode.
Further, reading a segment of binary data from the first byte buffer and converting the segment of binary data to an unsigned integer to obtain a first data segment, comprising:
acquiring a first parameter, wherein the first parameter is used for determining a starting byte of data reading;
reading binary data with a second preset bit width from the first byte buffer zone based on the first parameter;
and converting the read binary data with the second preset bit width into unsigned integers to obtain a first data segment.
Further, when the binary data with the second preset bit width is read from the first byte buffer area, if the initial word reaches the end of one byte, the next byte is automatically skipped to start reading the data.
Further, converting the first data segment into binary data with a first preset bit width, and storing the binary data with the first preset bit width in the second byte buffer area according to the sequence of the big end mode, including:
acquiring a second parameter, wherein the second parameter is used for determining a start byte of data coding;
converting the first data segment into binary data with a first preset bit width bit by bit based on a second parameter to obtain a second data segment;
the second data segment is stored in the second byte buffer in order of the big-end pattern.
Further, reading a segment of binary data from the third byte buffer and converting the segment of binary data to an unsigned integer to obtain a second data segment, comprising:
acquiring a third parameter, wherein the third parameter is used for determining a starting byte of data reading;
reading binary data with a fourth preset bit width from a third byte buffer based on a third parameter;
and converting the read binary data with the fourth preset bit width into unsigned integers to obtain a third data segment.
Further, when the binary data with the fourth preset bit width is read from the third byte buffer, if the initial word reaches the end of one byte, the next byte is automatically skipped to start reading the data.
Further, converting the third data segment into binary data with a third preset bit width, and storing the binary data with the third preset bit width in the fourth byte buffer area according to the order of the small end mode, including:
acquiring a fourth parameter, wherein the fourth parameter is used for determining a start byte of data coding;
converting the third data segment into binary data with a third preset bit width bit by bit based on a fourth parameter to obtain a fourth data segment;
the fourth data segment is stored in the second byte buffer in order of the big-end pattern.
The beneficial effects of the invention are as follows:
(1) The invention provides a general conversion method of data streams at large and small ends, which is used for assigning a large-end or small-end byte stream corresponding to the input of data to be output, and can be used for carrying out data conversion at the large and small ends each time when meeting the scene of data conversion at the large and small ends, thereby greatly reducing the work of developers, improving the development efficiency and shortening the development time;
(2) The invention can convert the data between the small end sequence (Little Endian) and the Big end sequence (Big Endian), and realize the Big end data stream coding and the small end data stream coding according to the initial word, the initial bit and the width.
Drawings
FIG. 1 is a flow chart of the encoding steps of the large end data stream of the present invention;
fig. 2 is a flowchart of the small end data stream encoding step of the present invention.
Detailed Description
The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments, and it is apparent that the described embodiments are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by a person skilled in the art without any inventive effort, are intended to be within the scope of the present invention, based on the embodiments of the present invention.
Referring to fig. 1 to 2, the present invention provides a method for converting a data stream at a size end:
a conversion method of large-end and small-end data streams comprises a large-end data stream coding step and a small-end data stream coding step.
As shown in fig. 1, the large-end data stream encoding step includes S100 to S200.
S100, reading a section of binary data from the first byte buffer area, and converting the section of binary data into an unsigned integer to obtain a first data section.
In some embodiments, reading a segment of binary data from a first byte buffer and converting the segment of binary data to an unsigned integer, resulting in a first data segment, comprising: acquiring a first parameter, wherein the first parameter is used for determining a starting byte of data reading; reading binary data with a second preset bit width from the first byte buffer zone based on the first parameter; and converting the read binary data with the second preset bit width into unsigned integers to obtain a first data segment.
In some embodiments, a first function is defined, the function of which is to read a piece of binary data from a first byte buffer, convert the piece of binary data to an unsigned integer, and then return. The specific process is as follows: the first function determines from which byte to start reading according to the input first parameter, then fetches binary data of a specified bit width in the byte, then converts the fetched binary data into an unsigned integer, and stores the unsigned integer to a corresponding position in a return value, which is the read binary data. If the start word reaches the end of one byte during the process of reading binary data, the next byte is automatically skipped.
In the process of reading binary data, a first value is calculated according to a start word, a start bit, a deviation bit and the like, wherein the first value represents the bit number of the binary data which should be shifted leftwards in a return value, so as to ensure that the return values are arranged according to the reading sequence of the data from a buffer zone.
S200, converting the first data segment into binary data with a first preset bit width, and storing the binary data with the first preset bit width into a second byte buffer area according to the sequence of the big end mode.
The order of the big-end mode means the order from the high order to the low order.
In some embodiments, converting the first data segment into binary data of a specified bit width and storing the binary data of the specified bit width in the second byte buffer in order of the big-end pattern includes: acquiring a second parameter, wherein the second parameter is used for determining a start byte of data coding; converting the first data segment into binary data with a first preset bit width bit by bit based on a second parameter to obtain a second data segment; the second data segment is stored in the second byte buffer in order of the big-end pattern.
In some embodiments, a second function is defined, the function of the second function being to encode the first unsigned integer as binary data of a specified bit width and store the segment of binary data in a second byte buffer. The specific process is as follows: the second function determines from which of itself the data should be encoded according to the inputted second parameter, then converts the data into binary data bit by bit, and stores the resulting binary data in the buffer in order of the big-end pattern. Finally, the unsigned integer is encoded in the specified bit width and stored in the second byte buffer.
In the storing process, the second function calculates the byte and the index of the bit where the current bit is located, and stores the binary data obtained by calculation to the corresponding position in the second byte buffer area by using an OR operator.
As shown in fig. 2, the small-end data stream encoding step includes S300 to S400.
S300, reading a section of binary data from the third byte buffer area, and converting the section of binary data into an unsigned integer to obtain a third data section.
In some embodiments, reading a segment of binary data from the third byte buffer and converting the segment of binary data to an unsigned integer to obtain a second segment of data, comprising: acquiring a third parameter, wherein the third parameter is used for determining a starting byte of data reading; reading binary data with a fourth preset bit width from a third byte buffer based on a third parameter; and converting the read binary data with the fourth preset bit width into unsigned integers to obtain a third data segment.
In some embodiments, a third function is defined that functions to read a piece of binary data from the third byte buffer and convert the piece of binary data to an unsigned integer and then return. The specific process is as follows: the third function first determines from which byte to start reading according to the third parameter input, then fetches binary data of a specified bit width in the byte, then converts the fetched binary data into an unsigned integer, and finally stores the unsigned integer in a corresponding position in the return value. If the start word reaches the end of one byte during the process of reading binary data, the next byte is automatically skipped.
In the process of reading binary data, a first value is calculated according to a start word, a start bit, a deviation bit and the like, wherein the first value represents the bit number of the binary data which should be shifted leftwards in a return value, so as to ensure that the return values are arranged according to the reading sequence of the data from a buffer zone.
S400, converting the third data segment into binary data with a third preset bit width, and storing the binary data with the third preset bit width into a fourth byte buffer area according to the sequence of the small end modes.
The order of the small-end mode refers to storing the low-order bytes of the data first and then storing the high-order bytes.
In some embodiments, converting the third data segment into binary data of a specified bit width and storing the binary data of the specified bit width in order of the small end pattern into the fourth byte buffer comprises: acquiring a fourth parameter, wherein the fourth parameter is used for determining a start byte of data coding; converting the third data segment into binary data with a third preset bit width bit by bit based on a fourth parameter to obtain a fourth data segment; the fourth data segment is stored in the second byte buffer in order of the big-end pattern.
In some embodiments, a fourth function is defined that functions to encode an unsigned integer as binary data of a specified bit width and store it in a fourth byte buffer. The specific process is as follows: the fourth function determines from which byte the encoding should be started according to the inputted fourth parameter, then converts the data into binary data bit by bit, and stores the resulting binary data in the fourth byte buffer in order of the small-end pattern. Finally, the unsigned integer is encoded in the specified bit width and stored in the fourth byte buffer.
In the storing process, the fourth function calculates the byte and the index of the bit where the current bit is located, and stores the binary data obtained by calculation to the corresponding position in the fourth byte buffer area by using an OR operator.
The foregoing is merely a preferred embodiment of the invention, and it is to be understood that the invention is not limited to the form disclosed herein but is not to be construed as excluding other embodiments, but is capable of numerous other combinations, modifications and environments and is capable of modifications within the scope of the inventive concept, either as taught or as a matter of routine skill or knowledge in the relevant art. And that modifications and variations which do not depart from the spirit and scope of the invention are intended to be within the scope of the appended claims.

Claims (5)

1. The method for converting the large-end data stream and the small-end data stream is characterized by comprising a large-end data stream encoding step and a small-end data stream encoding step;
the large end data stream encoding step comprises the following steps:
reading a section of binary data from a first byte buffer zone, and converting the section of binary data into unsigned integers to obtain a first data section;
converting the first data segment into binary data with a first preset bit width, and storing the binary data with the first preset bit width into a second byte buffer area according to the sequence of the big end mode;
converting the first data segment into binary data with a first preset bit width, and storing the binary data with the first preset bit width into a second byte buffer area according to the sequence of the big end mode, wherein the method comprises the following steps:
acquiring a second parameter, wherein the second parameter is used for determining a start byte of data coding;
converting the first data segment into binary data with a first preset bit width bit by bit based on a second parameter to obtain a second data segment;
storing the second data segment in the order of the big end pattern into a second byte buffer;
the step of encoding the small-end data stream comprises the following steps:
reading a section of binary data from the third byte buffer zone, and converting the section of binary data into unsigned integers to obtain a third data section;
converting the third data segment into binary data with a third preset bit width, and storing the binary data with the third preset bit width into a fourth byte buffer area according to the sequence of the small end mode;
converting the third data segment into binary data with a third preset bit width, and storing the binary data with the third preset bit width into a fourth byte buffer area according to the order of the small end mode, wherein the method comprises the following steps:
acquiring a fourth parameter, wherein the fourth parameter is used for determining a start byte of data coding;
converting the third data segment into binary data with a third preset bit width bit by bit based on a fourth parameter to obtain a fourth data segment;
the fourth data segment is stored in the second byte buffer in order of the big-end pattern.
2. The method of claim 1, wherein reading a piece of binary data from the first byte buffer and converting the piece of binary data to an unsigned integer to obtain the first data segment, comprising:
acquiring a first parameter, wherein the first parameter is used for determining a starting byte of data reading;
reading binary data with a second preset bit width from the first byte buffer zone based on the first parameter;
and converting the read binary data with the second preset bit width into unsigned integers to obtain a first data segment.
3. The method of claim 2, wherein when the binary data with the second predetermined bit width is read from the first byte buffer, if the start word reaches the end of one byte, the method automatically jumps to the next byte to start reading the data.
4. The method of claim 1, wherein reading a piece of binary data from the third byte buffer and converting the piece of binary data to an unsigned integer to obtain the second data piece, comprising:
acquiring a third parameter, wherein the third parameter is used for determining a starting byte of data reading;
reading binary data with a fourth preset bit width from a third byte buffer based on a third parameter;
and converting the read binary data with the fourth preset bit width into unsigned integers to obtain a third data segment.
5. The method of claim 4, wherein when reading binary data with a fourth predetermined bit width from the third byte buffer, if the start word reaches the end of one byte, the method automatically jumps to the next byte to start reading data.
CN202311846152.9A 2023-12-29 2023-12-29 Conversion method of data streams at large end and small end Active CN117492702B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311846152.9A CN117492702B (en) 2023-12-29 2023-12-29 Conversion method of data streams at large end and small end

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311846152.9A CN117492702B (en) 2023-12-29 2023-12-29 Conversion method of data streams at large end and small end

Publications (2)

Publication Number Publication Date
CN117492702A CN117492702A (en) 2024-02-02
CN117492702B true CN117492702B (en) 2024-04-02

Family

ID=89680416

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311846152.9A Active CN117492702B (en) 2023-12-29 2023-12-29 Conversion method of data streams at large end and small end

Country Status (1)

Country Link
CN (1) CN117492702B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5644522A (en) * 1993-11-30 1997-07-01 Texas Instruments Incorporated Method, apparatus and system for multiply rounding using redundant coded multiply result
WO2002003327A2 (en) * 2000-06-29 2002-01-10 The Trustees Of Columbia University In The City Of New York Method and system for analyzing multi-dimensional data
US6708273B1 (en) * 1997-09-16 2004-03-16 Safenet, Inc. Apparatus and method for implementing IPSEC transforms within an integrated circuit
CN109818930A (en) * 2018-12-27 2019-05-28 南京信息职业技术学院 Communication text data transmission method based on TCP protocol
WO2020097232A1 (en) * 2018-11-07 2020-05-14 Futurewei Technologies, Inc. Header parameter set for video coding
CN111865559A (en) * 2020-06-16 2020-10-30 郑州信大捷安信息技术股份有限公司 Rapid realization method and device for SM4 algorithm
CN112052010A (en) * 2020-09-25 2020-12-08 中国直升机设计研究所 ICD byte order automatic conversion method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6272257B1 (en) * 1997-04-30 2001-08-07 Canon Kabushiki Kaisha Decoder of variable length codes

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5644522A (en) * 1993-11-30 1997-07-01 Texas Instruments Incorporated Method, apparatus and system for multiply rounding using redundant coded multiply result
US6708273B1 (en) * 1997-09-16 2004-03-16 Safenet, Inc. Apparatus and method for implementing IPSEC transforms within an integrated circuit
WO2002003327A2 (en) * 2000-06-29 2002-01-10 The Trustees Of Columbia University In The City Of New York Method and system for analyzing multi-dimensional data
WO2020097232A1 (en) * 2018-11-07 2020-05-14 Futurewei Technologies, Inc. Header parameter set for video coding
CN109818930A (en) * 2018-12-27 2019-05-28 南京信息职业技术学院 Communication text data transmission method based on TCP protocol
CN111865559A (en) * 2020-06-16 2020-10-30 郑州信大捷安信息技术股份有限公司 Rapid realization method and device for SM4 algorithm
CN112052010A (en) * 2020-09-25 2020-12-08 中国直升机设计研究所 ICD byte order automatic conversion method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
嵌入式应用软件数据大小端转换方法研究;王禹君;《天津市电子工业协会2023年年会论文集》;20230715;1-4 *
面向非手机移动终端MMS传输技术的研究;魏凯;《中国优秀硕士学位论文全文数据库》;20090430;I136-593 *

Also Published As

Publication number Publication date
CN117492702A (en) 2024-02-02

Similar Documents

Publication Publication Date Title
CN105634499B (en) Data conversion method based on new short floating point type data
US10528539B2 (en) Optimized selection of hash collision chains
CN106155635B (en) Data processing method and device
JP3505266B2 (en) Program execution device
CN111008230B (en) Data storage method, device, computer equipment and storage medium
US7773005B2 (en) Method and apparatus for decoding variable length data
US20090112897A1 (en) Data sequence compression
CN110825323B (en) Storage and reading method of floating point number data and computer readable storage medium
JP3189876B2 (en) Variable length code decoding circuit
US20200294629A1 (en) Gene sequencing data compression method and decompression method, system and computer-readable medium
CN117492702B (en) Conversion method of data streams at large end and small end
CN111600610B (en) Universal coding method, system and electronic equipment for variable-length integers
JP2009093513A (en) Method for reducing instruction bit length
JPWO2013190690A1 (en) Encoding device, decoding device, encoding method, encoding program, decoding method, and decoding program
CN115765754A (en) Data coding method and coded data comparison method
CN113296732B (en) Data processing method and device, processor and data searching method and device
CN114692077A (en) Matrix calculation device, method, system, circuit, chip and equipment
CN114070470A (en) Encoding and decoding method and device
CN111310909A (en) Floating point number conversion circuit
KR102656567B1 (en) Apparatus for enabling the conversion and utilization of various formats of neural network models and method thereof
JPH06217110A (en) Image converting method
US7375657B2 (en) Method and system for performing streaming of encoded data
JPH09326707A (en) Variable length coding/decoding arithmetic processing unit
JPH07303045A (en) Huffman decoder
CN117251210A (en) Data processing method, processor, electronic device and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant