Number system converter: binary, hex, octal, decimal, BCD and REAL
Convert PLC data types (INT, DINT, LINT, WORD, REAL and LREAL IEEE 754, BCD) between decimal, binary, hexadecimal and octal, toggling their bits.Version 2 · First version: November 17, 2026 · Remastered: November 17, 2026
A PLC, a drive or an instrument does not store numbers: it stores bits. What we see as 1234, 16#04D2 or 2#0000_0100_1101_0010 is the same 16-bit pattern written in decimal, hexadecimal or binary. With this calculator you choose the IEC 61131-3 data type (INT, DINT, WORD, REAL, BCD…), type the number in whichever base you have and get all the others. You can also tap the bits on the board one by one, like switches, and watch the value change.
How to use the calculator
- Choose the data type: the same as the variable in the PLC. The bits are the same, but an INT, a WORD, a REAL or a BCD read them differently.
- Type the number in any field: decimal, hexadecimal, binary or octal. The one you type is the input and the other three are calculated. In hex,
16#04D2,0x4D2and4D2all work; in binary you can separate the digits with spaces or_. - Or tap the bits on the board: each tap switches that bit from 0 to 1 (or from 1 to 0). The bits are grouped by byte (8 bits) and under each byte is its value in hex and decimal: in 16#0217, byte 1 is 16#02 = 2 and byte 0 is 16#17 = 23.
- The results show the size, the bits set to 1, the range of the type and, for REAL and LREAL, the sign, exponent, mantissa and rounding error.
If you change the type, the calculator rereads the last value you typed: if it was the decimal, it finds its bits in the new type; if it was the bits, it tells you what they mean in the new type. So you see at once that 16#FFFF is 65,535 in a WORD and −1 in an INT.
Positional number systems
Decimal, binary, octal and hexadecimal are the same idea: a number is a row of digits and each digit is worth more the further left it is. The only difference is the base b, how many different digits there are:
For example, 16#04D2 = 4 · 16² + 13 · 16¹ + 2 · 16⁰ = 1024 + 208 + 2 = 1234. To go from decimal to another base, divide by the base again and again and read the remainders from bottom to top.
| Decimal | Binary | Octal | Hexadecimal | BCD |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | 0000 |
| 1 | 0001 | 1 | 1 | 0001 |
| 2 | 0010 | 2 | 2 | 0010 |
| 3 | 0011 | 3 | 3 | 0011 |
| 4 | 0100 | 4 | 4 | 0100 |
| 5 | 0101 | 5 | 5 | 0101 |
| 6 | 0110 | 6 | 6 | 0110 |
| 7 | 0111 | 7 | 7 | 0111 |
| 8 | 1000 | 10 | 8 | 1000 |
| 9 | 1001 | 11 | 9 | 1001 |
| 10 | 1010 | 12 | A | 0001 0000 |
| 11 | 1011 | 13 | B | 0001 0001 |
| 12 | 1100 | 14 | C | 0001 0010 |
| 13 | 1101 | 15 | D | 0001 0011 |
| 14 | 1110 | 16 | E | 0001 0100 |
| 15 | 1111 | 17 | F | 0001 0101 |
Binary (base 2)
It has only two digits, 0 and 1, the two states of a bit: contact open or closed, 0 V or 24 V. Each bit is worth twice the one to its right: 1, 2, 4, 8, 16… The rightmost bit (B0) is the least significant and the leftmost the most significant. It is the base for reading alarm or status words bit by bit.
Hexadecimal (base 16)
It uses the digits 0 to 9 and the letters A (10) to F (15). Since 16 = 2⁴, each hex digit is exactly 4 bits (a nibble): a BYTE takes 2 digits, a WORD 4 and a DWORD 8. That is why it is the short way of writing binary in PLCs, Modbus frames and memory dumps.
Octal (base 8)
Digits 0 to 7; each one is 3 bits. It is rare today, but it lives on in Linux file permissions (755), in some old PLCs that numbered their inputs and outputs in octal (no 8 or 9) and in avionics codes.
BCD (binary-coded decimal)
It is not a base: each decimal digit takes 4 bits of its own. 1234 in BCD is 0001 0010 0011 0100 = 16#1234: read in hex, it looks like the decimal number. Space is wasted (nibbles A to F are not valid), but it is very handy for 7-segment displays, thumbwheel switches, real-time clocks and the timers and counters of some PLCs. A WORD holds 0 to 9999 in BCD; a DWORD, 0 to 99,999,999.
IEC 61131-3 data types
The IEC 61131-3 standard (PLC programming languages) defines the elementary data types used by TIA Portal, Studio 5000, CODESYS, TwinCAT, Sysmac Studio and the other environments. The calculator includes these:
| Type | Bits | Range | Used for |
|---|---|---|---|
| SINT / USINT | 8 | −128 to 127 / 0 to 255 | Small counters, codes |
| INT / UINT | 16 | −32,768 to 32,767 / 0 to 65,535 | Analog values (0 to 27,648 in Siemens), setpoints |
| DINT / UDINT | 32 | −2,147,483,648 to 2,147,483,647 / 0 to 4,294,967,295 | Part counters, encoder positions |
| LINT / ULINT | 64 | −9.22 × 10¹⁸ to 9.22 × 10¹⁸ / 0 to 1.84 × 10¹⁹ | Energy counters, timestamps in ns |
| BYTE, WORD, DWORD, LWORD | 8, 16, 32, 64 | 16#00 to 16#FF… (no numeric value) | Bit strings: alarms, status, masks |
| REAL | 32 | ±1.18 × 10⁻³⁸ to ±3.40 × 10³⁸ (about 7 digits) | Measurements with decimals, PID, scaling |
| LREAL (double) | 64 | ±2.23 × 10⁻³⁰⁸ to ±1.80 × 10³⁰⁸ (about 16 digits) | Calculations that need precision, totalizers |
| BCD (in a WORD or DWORD) | 16 or 32 | 0 to 9999 / 0 to 99,999,999 | Displays, thumbwheels, clocks |
The standard also has BOOL (1 bit), the date and time types (TIME, DATE, TOD, DT) and the text types (STRING and WSTRING, a row of ASCII or Unicode characters, not a number).
To write a number in another base, the standard puts the base in front with a hash sign: 16#FF, 2#1111_1111 and 8#377 are all 255. The underscore is only for readability. The type can go in front too: INT#-5, WORD#16#00FF.
Signed integers: two's complement
Signed integers (SINT, INT, DINT) store negative numbers in two's complement: the highest bit is worth −2ⁿ⁻¹ instead of +2ⁿ⁻¹. If it is 1, the number is negative. In practice, a negative number is 2ⁿ minus its absolute value:
So in an INT (n = 16): −1 is 65,536 − 1 = 65,535 = 16#FFFF; −32,768 is 16#8000. To change the sign by hand, invert all the bits and add 1. The advantage is that the processor adds and subtracts the same way with or without sign. The danger is overflow: 32,767 + 1 in an INT gives −32,768.
Real numbers: the IEEE 754 standard
The IEC 61131-3 REAL is the single-precision floating-point number of the IEEE 754 standard (IEC 60559), and LREAL is the double-precision one (C's double). The 32 bits of a REAL are split into three fields:
- Sign (bit 31): 0 positive, 1 negative.
- Exponent (bits 30 to 23, 8 bits): stored with a bias of 127, so the actual exponent is E − 127.
- Mantissa (bits 22 to 0, 23 bits): the fraction f of the number 1.f in binary. The leading 1 is not stored (hidden bit), so the precision is 24 bits, about 7 decimal digits.
LREAL does the same with 64 bits: 1 sign bit, 11 exponent bits (bias 1023) and 52 mantissa bits, about 16 decimal digits: value = (−1)ˢ × 2^(E − 1023) × 1.f.
Example: 1.0 is 16#3F80_0000 (sign 0, E = 127, f = 0). And 0.1 is 16#3DCC_CCCD: sign 0, E = 123 (2⁻⁴) and mantissa 1.6000000238. It is not exact, because 0.1 has endless digits in binary; the REAL stores 0.100000001490116, and the calculator shows you that rounding error. In LREAL, 0.1 is 16#3FB9_9999_9999_999A and the error drops to 5.6 × 10⁻¹⁸.
| Exponent E | Mantissa f | Meaning |
|---|---|---|
| 0 | 0 | Zero (+0 or −0) |
| 0 | ≠ 0 | Subnormal: (−1)ˢ × 2⁻¹²⁶ × 0.f (below 1.18 × 10⁻³⁸) |
| 1 to 254 | any | Normal number |
| 255 | 0 | Infinity (+∞ or −∞) |
| 255 | ≠ 0 | NaN (not a number) |
ABS(a − b) < 0.0001. And do not use REAL for large counters: from 16,777,216 (2²⁴) on it can no longer add 1.Byte order: Modbus, Siemens and Intel
When a 32-bit value travels between devices, it is sent in bytes or 16-bit words, and each manufacturer orders them its own way. Siemens and Modbus send the high byte first (big-endian); Intel processors and many PC-based PLCs store the low byte first (little-endian). In Modbus, a REAL or DINT also takes two registers, and some devices send the low register first.
If a REAL read over Modbus comes out as a nonsense number, try swapping the two registers: 16#3DCC_CCCD (0.1) read with the words swapped is 16#CCCD_3DCC, which gives −107,605,600. Type the hex value into the calculator with the words swapped and see whether it matches.
Common mistakes
- Reading a negative INT as a WORD: −1 comes out as 65,535. The bits are the same; change the variable type.
- Overflowing an INT: 200 × 200 = 40,000 does not fit in an INT and gives −25,536. Use DINT for intermediate results.
- Sending BCD to a display that expects binary (or the other way round): 16#0099 is 153 in binary and 99 in BCD.
- Converting a REAL to INT without rounding: REAL_TO_INT rounds, but TRUNC drops the decimals; 2.7 gives 3 or 2 depending on the function.
Frequently asked questions
How do you convert binary to hexadecimal?
Group the bits in fours starting from the right and replace each group (nibble) with its hex digit: 0100 1101 0010 is 4D2. The other way round, each hex digit is four bits.
Why is −1 in an INT FFFF?
Because signed integers are stored in two's complement: a negative number is 2ⁿ minus its absolute value. In 16 bits, 65,536 − 1 = 65,535 = 16#FFFF. The highest bit (B15) set to 1 means it is negative.
Why is 0.1 not stored exactly in a REAL?
Because 0.1 in binary has endless digits (0.000110011…), just like 1/3 in decimal. A REAL only has 24 mantissa bits, so it stores 0.100000001490116, the nearest number that fits. That is why REALs should never be compared with “=”.
What is the difference between WORD and INT?
Both have 16 bits. WORD is a bit string with no numeric meaning (alarms, status, masks) and the standard does not allow arithmetic on it; INT is a signed integer from −32,768 to 32,767. The same bits, 16#FFFF, are 65,535 read as WORD or UINT and −1 read as INT.
What is BCD and where is it used?
Binary-coded decimal: each decimal digit takes 4 bits, so 1234 is stored as 16#1234. It is used by 7-segment displays, thumbwheel switches, real-time clocks and the timers of some PLCs.
How do I write a number in another base in a PLC?
IEC 61131-3 puts the base in front with a hash sign: 16#FF, 2#1111_1111 and 8#377 are all 255. The underscore is only a separator for readability. The type can be given too: INT#−5, WORD#16#00FF.
Version history
- Version 2 · November 17, 2026: 64 bits (LINT, ULINT, LWORD y LREAL) y bits agrupados por byte
- Version 1 · November 17, 2026: Primera versión, hasta 32 bits
