Data type description
Data types are important concepts in programming languages, and they serve several purposes:
- Memory allocation: Different data types require different amounts of memory in the computer’s memory. For example, integers typically require 4 bytes of memory, while floating-point numbers may require 8 bytes or more. Therefore, using the correct data type can ensure memory usage efficiency and program performance.
- Data processing: Different data types can support different operations and calculations. For example, integers can be used in arithmetic operations such as addition, subtraction, multiplication, and division, while strings can be used in operations such as concatenation and splitting. Using the correct data type can ensure the accuracy and effectiveness of data processing.
- Input/output: Different data types require different input/output methods. For example, integers can be read/written using standard input/output, while images need to be read/written using specific image formats. Using the correct data type can ensure that programs can read and write data correctly.
- Code logic: Different data types correspond to different meanings and uses, so choosing the correct data type is important in reflecting the code logic and intent.For example, boolean variables are typically used in flow control and logical judgments, while integers and floating-point numbers are typically used in mathematical calculations.
In summary, selecting and using the correct data type is a crucial step in programming, as it directly affects program correctness, performance, and maintainability. The following are the data types for Neuron:
Data type | Data range | Occupied bytes | Data example |
---|---|---|---|
INT8 | -128~127 | 1 | For example, 100 is [0x64] |
UINT8 | 0~255 | 1 | For example, 100 is [0x64] |
INT16 | -32768~32767 | 2 | For example, 100 is [0x64] [0x00] |
UINT16 | 0~65535 | 2 | For example, 100 is [0x64] [0x00] |
INT32 | -2147483648~2147483647 | 4 | For example, 100 is [0x64] [0x00] [0x00] [0x00] [0x00] |
UINT32 | 0~4294967295 | 4 | For example, 100 is [0x64] [0x00] [0x00] [0x00] [0x00] |
INT64 | -9223372036854775808~9223372036854775808 | 8 | For example, 100 is [0x64] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] |
UINT64 | 0~18446744073709551615 | 8 | For example, 100 is [0x64] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] |
FLOAT (real) | -3.40E+38~+3.40E+38 | 4 | For example, 100 is [0x00] [0x00] [0xC8] [0x42] |
DOUBLE (long real) | -1.79E+308~+1.79E+308 | 8 | For example, 100 is [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x59] [0x40] |
BIT | 0/1 | 1 bit | The 0th bit of 0x11 is 1 |
BOOL | True/False | 1 bit | The 0th bit of 0x11 is True |
WORD | 0~65535 | 2 | For example, 100 is [0x64] [0x00] |
DWORD | 0~4294967295 | 4 | For example, 100 is [0x64] [0x00] [0x00] [0x00] [0x00] |
LWORD | 0~18446744073709551615 | 8 | For example, 100 is [0x64] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] [0x00] |
TIP
Writing a program requires an understanding of the essence of data. For example, the data essence of the number 1065353216 under the int data type is “00 00 80 3F,” while the data essence of the number 1 under the float data type is also “00 00 80 3F.” However, when faced with the data “00 00 80 3F,” it is impossible to know what it represents. One might assume that 1065353216 is too large and must be a float value of 1, but this is a subjective judgment made by humans, and the program itself is unaware. Therefore, when interpreting data, it is important to use the same data type as the original data to avoid producing garbled output. In other words, the data should be parsed using the same data type it was originally encoded as.
About data arrangement
There is an example in the above data table. The essence of int data 100 is “64 00 00”, but from our human senses, it should be “00 00 00 64”, which is more reasonable. The habit of most people is to have high positions in the front and low positions in the back. However, this is only a rule. Data storage can have multiple permutations, generally divided into three types:
- Small end arrangement: Typical representation is C # language, Mitsubishi PLC.
- Large end arrangement: typical representative is Siemens PLC.
- Other irregularities: Typical examples are modbus devices.
Neuron supports multiple byte orders, as shown in the following table:
ENDIAN
Byte order, applicable to int16/uint16/int32/uint32/float data types. See the table below for detailed instructions.
Symbol | Byte order | Supported data types | Remarks |
---|---|---|---|
#B | 2,1 | int16/uint16 | |
#L | 1,2 | int16/uint16 | Default byte order |
#LL | 1,2,3,4 | int32/uint32/float | Default byte order |
#LB | 2,1,4,3 | int32/uint32/float | |
#BB | 3,4,1,2 | int32/uint32/float | |
#BL | 4,3,2,1 | int32/uint32/float |
.LEN[H][L][D][E]
When the data type is STRING, .LEN is a required entry, indicating the byte length required for a string. Each register contains four storage methods: H, L, D, and E, as shown in the following table.
Symbol | Description |
---|---|
H | A register stores two bytes, with the high byte first and the low byte second |
L | A register stores two bytes, with the low byte first and the high byte second |
D | A register stores one byte and is stored at a low byte |
E | A register stores one byte and is stored in high bytes |