# Transmit Two Numbers Using a Single Number

I am working with an industrial temperature controller, a PLC, and a limited number of numeric inputs. I have two channels on my temperature controller, each of which can generate an integer error code. Unfortunately, I only have one integer input available on my PLC with which to receive these two codes. I can do math functions on either end to distinguish the two numbers from one another, but may only transmit one number from the temperature controller to the PLC. Is this possible?

There are other hardware changes I could make to get around this problem, but I thought it could make for an elegant and efficient solution. Here's some additional info:

## Transmit Side (Temperature Controller)

Each channel (A and B) on the temperature controller contains an integer value for the error code:

• No Error = 61
• Valid Error Codes = 9, 32, 65, 127, 139, 140

And these are the math functions available to me on this end:

• Multiply/Divide
• Average
• Absolute Difference (|A-B|)
• Square Root

I must perform these functions one at a time, so the simpler the better. The number being output is limited to a 16-bit unsigned integer (0 to 65,535).

I would combine A and B to produce a value C, perhaps by doing something like Ax + By = C, and transmit this to the PLC. (Of course, Ax * By = C make them much easier to factor out, but I quickly violate my maximum value limitation.)

I have a few more math functions available to me in the PLC:

• Multiply/Divide
• Modulo
• Square Root
• Exponent (x^y)
• Absolute Value
• Cos, Sin, Tan, ArcCos, ArcSin, ArcTan
• Natural Log
• Log Base 10
• Truncate (drop values after decimal)

In the PLC I can write an expression that will output a value. I can also perform some initial checks, for example:

If (C mod x = 0 AND C mod y = 0)
Then compute expressions 1 (to get A) and 2 (to get B)

ElseIf (C mod x = 0)
Then compute expressions 3 (to get A) and 4 (to get B)

ElseIf (C mod y = 0)
Then compute expressions 5 (to get A) and 6 (to get B)

Since I know that x is related to A and y is related to B, through what mathematical operations can I create C and then translate C back into A and B?

• why not treat $A,B$ as two 8-bit unsigned integer and pack them together? i.e C = 256*A + B, then B = C mod 256, A = (C-B)/256. – achille hui Oct 19 '17 at 20:45
• @achillehui this is worthy of an answer in my opinion. – Dan A. Oct 19 '17 at 22:48

An usual way to encode two numbers $a,b$ into one, $x$, provided that at least one of $a$ or $b$ is bounded by a known number and non negative (say that $0\le a< M$), is the following:

Codification: $bM+a\to x$

Decodification: $b=x/M$ (integer division), $a=x\mod M$.

I don't know what kind of temperatures you want to handle.

Negative temperatures should not be a problem, but double check that how integer division and mod are implemented for negative numbers. The mod operation must always yield a non negative remainder, lesser than the divisor. For example $-7/5$ should be $-2$ and $-7\mod 5$ should be $3$.

Very high temperatures can be a problem. Since the greatest error code is $140$, $M=141$, and the maximum temperature should not be greater than $464$. ($464\cdot141+140=65534$).

• Thanks! This certainly solves the problem. For the record - I am only combining the error code values of channels A and B - the actual temperature values themselves get a dedicated input. So the maximum value of either integer is 140. – Dan A. Oct 19 '17 at 22:50