ControlsToolbox

Free tools for PLC programmers and controls engineers.

ControlsToolbox › PLC data type converter

PLC data type converter

See a PLC value at its full width, with every bit numbered. Integer mode shows signed, unsigned, hex and binary. Floating point mode breaks a REAL or LREAL into its sign, exponent and mantissa. Tap a bit to flip it. Word and byte swaps help when a Modbus device sends values in a different order.

Bits (bit 0 = least significant)

Value

Swapped orders

PLC integer and floating-point types

The calculator uses the IEC 61131-3 type names. Rockwell Logix has mostly used the signed names (SINT, INT, DINT, LINT, REAL), and newer controllers and firmware add unsigned types and LREAL; check your controller's documentation. Siemens TIA Portal and CODESYS also use the unsigned and bit-string types; TIA Portal writes them in mixed case, such as Int, DInt and Real.

TypeBitsRange
SINT8−128 to 127
USINT / BYTE80 to 255
INT16−32,768 to 32,767
UINT / WORD160 to 65,535
DINT32−2,147,483,648 to 2,147,483,647
UDINT / DWORD320 to 4,294,967,295
LINT64±9.22 × 10¹⁸
REAL32±3.4 × 10³⁸, ~7 digits
LREAL64±1.8 × 10³⁰⁸, 15–16 digits

Signed values and two's complement

A signed integer stores negative numbers in two's complement: invert every bit of the positive value and add 1. The top bit (bit 15 of an INT, bit 31 of a DINT) is then the sign. That is why the same 16 bits read as −1 for an INT and 65,535 for a UINT, and why an analog card's raw value can look wildly wrong when it is moved into the wrong type.

Example: DINT −1,234,567 is stored as 16#FFED_2979. Read as a UDINT, the same bits are 4,293,732,729.

How a REAL is stored (IEEE 754)

Integers and REALs use their bits completely differently, which is why the converter has separate Integer and Floating point modes. A REAL packs three fields into 32 bits:

FieldREAL bitsLREAL bitsWhat it holds
Sign31630 = positive, 1 = negative
Exponent30–23 (8)62–52 (11)Power of 2, stored with a bias of 127 (LREAL 1023)
Mantissa22–0 (23)51–0 (52)Fraction after an implied leading 1

The value is (−1)sign × 1.mantissa × 2exponent − 127. For example, 123.45 is stored as 16#42F6_E666:

A few bit patterns are special. An exponent of all zeros means zero, or a very small "subnormal" value. An exponent of all ones means infinity, if the mantissa is zero, or NaN (not a number), if it isn't. A NaN or a huge or tiny value is often the first sign that a value was read from the wrong registers.

Because the mantissa has 24 significant bits, counting the implied 1, a REAL holds about 7 decimal digits. Whole numbers are exact only up to 16,777,216, so a REAL used as a counter stops increasing by 1 there. An LREAL holds about 15–16 digits.

Modbus 32-bit word order

Modbus registers are 16 bits, so a DINT or REAL takes two registers. Modbus puts the high byte first inside each register, but it doesn't define which register comes first, so devices differ. If a flow meter's float reads as a huge or tiny number, try the swapped orders this calculator shows:

Pick the order that gives a sensible reading, then set that order in your Modbus driver, or swap the words or bytes in the PLC before using the value.

Frequently asked questions

What is the range of an INT and a DINT?

An INT is 16 bits: −32,768 to 32,767. A DINT is 32 bits: −2,147,483,648 to 2,147,483,647. The unsigned versions, UINT and UDINT, run from 0 to 65,535 and 0 to 4,294,967,295.

Why does my Modbus float read as a huge or tiny number?

The two 16-bit registers that make up the 32-bit value are probably in a different order than your driver expects. Enter the raw value and check the word-swapped (CDAB), byte-swapped (BADC) and fully reversed (DCBA) results to find the one that makes sense.

How do I convert hex to decimal for a PLC?

Choose the data type, set 'Enter as' to Hex and type the value. For example, choose INT and enter 16#FFFF: the calculator shows −1 signed and 65,535 unsigned, plus the binary and every bit.

How is a REAL stored in binary?

A REAL is a 32-bit IEEE 754 float: 1 sign bit, 8 exponent bits and 23 mantissa (fraction) bits. The value is (-1)^sign x 1.mantissa x 2^(exponent - 127). For example 123.45 is 16#42F6_E666: sign 0, exponent 133 (133 - 127 = 6) and mantissa 1.9289062, so 1.9289062 x 2^6 = 123.45.

Why does a REAL 0.1 actually store 0.100000001?

Most decimal fractions have no exact binary form, so a REAL stores the nearest value it can. 0.1 is stored as 0.100000001490116. A REAL keeps about 7 significant digits, and an LREAL about 15 to 16.

What does 16# mean in a PLC value?

16# is the IEC 61131-3 prefix for a hexadecimal literal, used in Rockwell, Siemens and CODESYS PLCs. 2# marks a binary literal.

More calculators