How do you convert decimal values to binary in LookoutDirect?

Brian Holt4 min read
HMI / SCADAOther ManufacturerTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A decimal value arrives in LookoutDirect, but you need to identify which individual bits are set. Extract each bit mathematically from the numeric value; do not treat a decimal-to-binary display as a way to bypass the controller’s I/O or data limits.

Check what the decimal value represents

First read the value shown in LookoutDirect and confirm its source address and meaning in the controller program. The example here uses VX0 (V40400) from a D2-240 CPU as a decimal word representing inputs. Your installation may use another address or a different data type; verify those details before applying the expressions.

  • If the value is a numeric word whose bits encode states, continue with bit extraction.
  • If LookoutDirect already exposes the individual I/O points, use those point values instead of decoding a word.
  • If the displayed number changes unexpectedly or does not match the controller’s value, resolve the address, data-type, or communications issue first. Decoding an incorrect value only produces plausible-looking wrong bits.

A word’s decimal value is the sum of its set-bit weights: bit 0 contributes 1, bit 1 contributes 2, bit 2 contributes 4, and so on. Extracting a bit tests whether its weight is present in the value.

Check whether you need bit states or a binary-looking display

Decide what the operator or diagnostic screen needs to show. For interlocks and status indicators, create one Boolean expression per bit. For a compact visual representation, combine the extracted bits into decimal digits 0 and 1. Those digits are a display encoding, not a new binary data type.

The reported LookoutDirect display constraint was eight digits. The demonstrated method therefore displays bits 0 through 7; it does not provide a full-width binary view of a larger word. If you need more bits, decode another group separately and give each displayed group a clear label. Do not assume that formatting a value as digits expands the underlying data width.

Check one bit with truncation and modulo

For bit number n in a nonnegative integer value V, use:

bit_n = mod(trunc(V / 2^n), 2)

The expression shifts the selected bit into the ones place by dividing by its weight, truncates the fractional part, then uses modulo 2 to return 0 or 1. The supplied LookoutDirect expression for bit 15 was:

if(mod(trunc(VX0/32768),2)=1,true,false)

Here, 32768 is 215. To test another bit, replace that divisor with the bit’s weight, 2n. For example, bit 0 uses divisor 1. Check the LookoutDirect expression editor’s accepted syntax and confirm that the input is an integer value; do not substitute a guessed function name if the expression is rejected.

  • If the result is 1, the selected bit is set.
  • If the result is 0, it is clear.
  • If the expression errors or returns a non-Boolean unexpectedly, check the function syntax, value type, and whether the expression references the intended address before expanding it to other bits.

Check the first eight bits with a grouped expression

For a decimal word displayed as the first eight bits, calculate from the highest bit downward so each lower bit uses the remainder after higher weights are removed. The demonstrated expressions are:

Bit7 = trunc(VX0/128)
Bit6 = trunc((VX0-Bit7*128)/64)
Bit5 = trunc((VX0-Bit7*128-Bit6*64)/32)
Bit4 = trunc((VX0-Bit7*128-Bit6*64-Bit5*32)/16)
Bit3 = trunc((VX0-Bit7*128-Bit6*64-Bit5*32-Bit4*16)/8)
Bit2 = trunc((VX0-Bit7*128-Bit6*64-Bit5*32-Bit4*16-Bit3*8)/4)
Bit1 = trunc((VX0-Bit7*128-Bit6*64-Bit5*32-Bit4*16-Bit3*8-Bit2*4)/2)
Bit0 = trunc((VX0-Bit7*128-Bit6*64-Bit5*32-Bit4*16-Bit3*8-Bit2*4-Bit1*2)/1)

Then assemble a readable sequence of decimal digits, with bit 7 at the left and bit 0 at the right:

Bin = Bit0*1+Bit1*10+Bit2*100+Bit3*1000+Bit4*10000+Bit5*100000+Bit6*1000000+Bit7*10000000

This construction makes the lowest bit the rightmost displayed digit. Label the bit order on the display; reversing the order is a common source of incorrect interpretation.

Check higher bits and verify the decoded states

For bits above bit 7, apply the modulo expression directly to the original word rather than attempting to extend the eight-digit display. If you need a second group, decode its bit positions separately and present it as a distinct group. Verify each group against the controller’s actual word or known input states before relying on it for operator decisions.

  1. Choose a bit whose state you can independently read from the controller or I/O status.
  2. Compare the LookoutDirect Boolean result with that state at both 0 and 1 conditions, if safely available during normal operation.
  3. Check a multi-bit value and confirm that each extracted bit matches the corresponding weight in the decimal value.
  4. Confirm the display labels and left-to-right order, then test any second group separately.

Do not use the encoded decimal-digit display as a control value or write it back as though it were the original word. Keep decoded indicators for visualization; retain the source word for logic that expects the numeric value.

FAQ: Decode decimal words in LookoutDirect

Why does LookoutDirect show decimal instead of binary?

The source is a numeric word displayed in decimal. Use mod(trunc(V/2^n),2) to extract bit n, or combine bit results into decimal digits for a visual 0/1 string.

How do I get bit 15 from a decimal value?

Divide the value by 32768, truncate, then take modulo 2: mod(trunc(V/32768),2). Use the Boolean form if(mod(trunc(V/32768),2)=1,true,false) where needed.

Why does my binary display stop after eight digits?

The demonstrated LookoutDirect approach is limited to an eight-digit display, covering bits 0 through 7. Decode and label another group separately when higher bits are required. Stop before using decoded values in control logic if the address, type, bit order, or expression result does not match the controller; consult the LookoutDirect documentation or official product support for the installed version.

Back to blog