Concatenate two 16 bit to 32bit

karthikmcl

Member
Join Date
Nov 2011
Location
*******
Posts
8
Hi,
I want to concatenate two 16bit int to 32bit Dint. Im using RSLogix 5000 V19.01.Is their any Instruction???

Thanks in Advance.

Regards,
Karthik
 
Can you tell us the tag names of the INTs?

If they are consecutive in an array, then you should be able to merely use the COPy with the first one as the source, the DINT as the destination, and a Length of 1 (the length is in reference to the destination data type).

If they are not consecutive, then you can MOV the least significant INT to the DINT first, then use BTD (bit field distribute) to move the 16 bits from the most significant INT into the DINT,

Or

CLR the DINT first, then MOV the most significant INT to the DINT first, then multiply by 2^16 to shift those bits to the high end of the DINT, then MVM the least significant INT into the lower end (masking out the higher bits so they are left intact).

There may be other simpler ways to do this, some other more experienced Logix5000 users may be able to add to the thread.

Paul
 
There may be other simpler ways to do this, some other more experienced Logix5000 users may be able to add to the thread.

Paul
I've no experience with Lgx5K but, would it not work to multiply what is to be the high-order word by 2^16 directly into the DINT then just add the low-order word to the DINT?
 
Yes Doug, that will work well.

CPT DintTag (IntTagHigh*65536)+IntTagLow

However if the Int16s are in an array then a COPy like Paul suggested will work very well.
 
I've no experience with Lgx5K but, would it not work to multiply what is to be the high-order word by 2^16 directly into the DINT then just add the low-order word to the DINT?
Doh!

Thanks, yes, I knew I was making it slightly too hard ... not enough caffeine ...:cool:
 
Yes Doug, that will work well.

CPT DintTag (IntTagHigh*65536)+IntTagLow

However if the Int16s are in an array then a COPy like Paul suggested will work very well.

Be warned! "CPT DintTag (IntTagHigh*65536)+IntTagLow" will only work provided the MSB of the words is not set. This changes the sign of the INT to -ve, and then gives the wrong result. It is a shame Logix5000 has such a small function library and does not allow UINT, UDINT, WORD or DWORD datatypes like other IEC compliant platforms do.
 
In RSLogix 5000, use the BTD instruction (Bit Field Distribute) That's what it is for. Works Great!

If you need an example, I can show you one.
 
AND IntTagHigh 16#0000FFFF DintTag
CPT DintTag (DintTag*65536)AND IntTagLow

will work if the sign bits are set in either integer.


BTD works great for apps like this, but it moves bits one at a time, so I wouldn't be surprised if it takes slightly longer to execute. You should consider who might be reading the program though, Bubba might scratch his head over one or the other and then your phone will be ringing at 3:00 A.M.
 
Last edited:
I used a BTD with a Banner camera measuring an angle. I got that phone call from Bubba, but it was way before beer:30 (on his end)
 
my curiosity compels me

. . I am curious....
. . I am used to using concatenation to join "non-numeric" bit patterns, like ascii characters. these, as such, do not have a sign bit. they r simply bit patterns.
. . what kind of data is it that u r concatenating?
. . does one of the words have a numerical "weight" above/below the other?
. . if the information is indeed numeric, would a floating point format be more useful?

thanks,
bill
 

Similar Topics

Has anyone concatenated two 16-bit (B3) words into one 32-bit (L) word in a Micrologix 1400? I do not want to add the values. I need to maintain...
Replies
4
Views
4,354
Hello All, I have a little problem that I need some help with. I have got a 17 digit number coming from a supplier. It's basically a barcode...
Replies
11
Views
2,929
Hi, I have a list selector which I want to display the recipe found inside a plc-5. The recipe is store in an ascii table with each character...
Replies
4
Views
1,377
I am trying to concatenate two INTs into one DINT I have try following Knowledgebase Article 552006 but I am not having any luck. I have found...
Replies
6
Views
2,938
Hi all, I have trouble compiling the following simple Cicode function in Citect V7.0r1. Compiling gives the error "Operand expected". FUNCTION...
Replies
1
Views
3,879
Back
Top Bottom