Share this

How are common number systems converted in a PLC?

2026-04-06 02:44:29 · · #1

Every number system contains two basic elements: cardinality and place value .

Radix: The number of digits used in a number system.

For example, the base of binary is 2; the base of decimal is 10.

Place value: The value represented by 1 in a number system (the value of its position).

For example, in the decimal system 123, the place value of 1 is 100, the place value of 2 is 10, and the place value of 3 is 1.

In binary 1011, the bit weight of the first 1 from the left is 8, the bit weight of the 0 is 4, the bit weight of the second 1 is 2, and the bit weight of the third 1 is 1.

Commonly used number systems in PLCs include: decimal, binary, hexadecimal, octal , etc.

In addition, BCD and ASCII codes are also used occasionally.

Decimal notation:

For example, 1234 = 1*103 + 2*102 + 3*101 + 4*100. When it reaches ten, it carries over one. The base number is 10. The individual numbers are 0-9. The coefficient of each number is multiplied by the base number (10) to the power of N, where N is the number of digits.

Binary notation:

For example, 1101 = 1*23 + 1*22 + 0*21 + 1*20 = 13. When the number reaches two, it carries over to the next position. The base is 2. A single number can only be 0 or 1. The coefficient of each bit is multiplied by the base (10) raised to the power of N, where N is the bit position. From the 3rd bit to 0, the values ​​are 8, 4, 2, and 1 respectively, so the binary representation is also 8421 code. If representing a signed number, the highest bit represents the sign: 0 for positive and 1 for negative. Positive numbers are represented in binary original code; negative numbers are stored in two's complement, which involves inverting each bit of the original code and adding 1.

Hexadecimal notation:

Hexadecimal is a base-16 system. It is generally represented by the numbers 0 to 9 and the letters A to F (or a to f), where A to F represent 10 to 15.

Octal notation:

Carry over when you reach eight. Single numbers range from 0 to 7. In PLCs, it's commonly used for addressing, but less frequently for data processing. BCD (Binary-Coded Decimal) code: also known as binary-coded decimal or base-20 code. It uses 4 binary bits to represent the 10 digits (0-9) of a single decimal number. Clocks are typically stored using BCD code.

ASCII (American Standard Code for Information Interchange):

ASCII is a computer encoding system based on the Latin alphabet, primarily used to display modern English and other Western European languages. It is the most widely used system today and is equivalent to the international standard ISO/IEC 646. In PLCs, data storage can only be in the form of 0s and 1s; other data can be converted from number systems to binary. However, the representation of letters and special symbols requires a set of conversion rules, hence the development of ASCII encoding by relevant standardization organizations in the United States.

Floating-point number (float):

Also known as a real number (REAL), a floating-point number is a numerical representation of a number belonging to a specific subset of rational numbers. In computers, it is used to approximate any real number. Specifically, this real number is obtained by multiplying an integer or fixed-point number (i.e., the mantissa) by an integer power of a certain base (usually 2 in computers). This representation is similar to scientific notation with a base of 10.

In binary scientific notation: S = M × 2^N

It mainly consists of three parts: sign bit + exponent (N) + mantissa (M). For float data, its binary representation is 32 bits, of which there is 1 sign bit, 8 exponent bits, and 23 mantissa bits.

Sign bit: 0 indicates positive, 1 indicates negative.

Exponent: Here, the exponent is represented using offset binary. For float data, the specified offset is 127. The exponent can be positive or negative. For 8-bit binary, its range is -128 to 127. For example, for float data, if the actual value of the exponent is 2, then adding 127 results in 129, and its exponent representation is 10000010.

Mantissa: Significant digits, i.e., some binary bits (binary bits after the decimal point). Since the integer part of M is always 1, this 1 is not stored.

For example

Converting the float data 125.5 to standard floating-point format, the binary representation of 125 is 1111101. The fractional part is represented as a binary 1 (multiplying the fractional part by 2; if less than 1, it becomes 0; if greater than 1, it becomes 1, and so on, multiplying by 2 until the fractional part becomes 0). Therefore, 125.5 in binary is 1111101.1. Since the integer part of the mantissa is always 1, it is represented as 1.1111011*2^6, with an exponent of 6. Adding 127 gives 133, which is represented as 10000101. Removing the integer part 1 from the mantissa, resulting in 1111011, and padding with 0s to make it 23 bits, gives 11110110000000000000000. Its binary representation is: 0 10000101 11110110000000000000000

So how are these number systems converted?

1. The method for converting decimal to binary is as follows:

The decimal number division by 2 and remainder method involves dividing a decimal number by 2, taking the remainder as the place value, and then dividing the quotient by 2 again. This process is continued until the quotient is 0. (See the diagram below for specific usage.)

2. The method for converting binary to decimal is as follows:

Expanding binary numbers according to their place values ​​and adding them together yields a decimal number. (See the diagram below for specific usage.)

3. The method for converting binary to octal is as follows:

Expanding and adding three binary digits according to their weights yields one octal digit. (Note: When converting three binary digits to octal, start the conversion from right to left, padding with zeros if necessary). (See the diagram below for specific usage.)

4. The method for converting octal to binary is as follows:

Octal numbers are converted to binary numbers by dividing by 2 and taking the remainder. Each octal number consists of 3 binary digits; if necessary, zeros are added to the leftmost side. (See the diagram below for specific usage.)

5. The method for converting binary to hexadecimal is as follows:

Similar to the binary-to-octal conversion method, octal uses a combination of three digits, while hexadecimal uses a combination of four digits. (Note: When converting 4-bit binary to hexadecimal, start the conversion from right to left, padding with 0s if necessary). (See the diagram below for specific usage.)

6. The method for converting hexadecimal to binary is as follows:

Hexadecimal numbers are converted to binary numbers by dividing by 2 and taking the remainder. Each hexadecimal number is represented by four binary digits; if necessary, zeros are added to the left. (See the diagram below for specific usage.)

7. There are two methods to convert decimal to octal or hexadecimal:

First: Indirect method—convert decimal to binary, and then from binary to octal or hexadecimal. Illustrated explanations of usage are omitted here.

Second: Direct method—Convert decimal to octal or hexadecimal by dividing by 8 or 16 and taking the remainder until the quotient is 0. (See the diagram below for specific usage.)

8. The method for converting octal or hexadecimal to decimal is as follows:

Expand octal and hexadecimal numbers according to their place values ​​and add them together to get a decimal number. (See the diagram below for specific usage.)

9. BCD code to decimal conversion:

Because BCD code uses four binary bits to represent one decimal digit, the conversion method is similar to the binary-to-hexadecimal "combining four bits into one" method. The four bits combined and then converted to decimal gives the decimal number. The above introduces commonly used number systems in PLCs and their conversion methods, aiming to help beginners understand the meaning of number systems and conversion rules. In actual use, the calculation can be easily performed using a programmer's calculator provided by the computer.


Read next

CATDOLL 128CM Emelie Open Eyes Type

Height: 128cm Weight: 19kg Shoulder Width: 30cm Bust/Waist/Hip: 57/52/63cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22