Converting DINT to INT

A DINT uses two consecutive %R registers. If the values in the registers are all between -32768 and +32767, then the data is all in the first register (the one with the lower address). If the data is outside that range, then you need to send it as 32-bit data anyway.

The most straightforward way I've found to convert from INT to DINT is to first convert from INT to REAL, then from REAL to DINT.
 
Re: Converting DINT to INT, Why?

abrier said:
I need to convert DINT's to INT's to provide MODBUS data registers. What is the best way to do that in a 90-30 / VersaPro project?

Why not send the DINT's as two consecutive words? Converting the DINTs to INTs is not a good idea as you will limit the values that can be trasfered to -32768 to 32767 as mentioned above.
 
do you really need DINT is INT not enough?
you can make it by dividing the DINT by 65536 and you will get two int.
also a simple mask by AND with the max INT (65535) you will get the low side and by shifting 16 places to right you will get the high part in sepaarate registers, however in modbus sending two registers is very easy .
 
Not Necessary, and a waste of time and a chance for errors.

shooter said:
do you really need DINT is INT not enough?
you can make it by dividing the DINT by 65536 and you will get two int.
also a simple mask by AND with the max INT (65535) you will get the low side and by shifting 16 places to right you will get the high part in sepaarate registers, however in modbus sending two registers is very easy .

Why? Go back to what Steve said.

Why not just send the 2 16 bit words as they are?

If a DINT is stored in R2 and R3. The R2 already is equal to DINT(R3:R2) and 65535 and R3 already is equal to DINT(R3:R2)/65536 or DINT(R3:R2) SHR 16. Note, the shift must be a signed or arithmetic shift.

Isn't any one curious?. Doesn't any one enter a number in one format like DINT and then view the data in another format such as floats, unsigned 16 bit, unsigned 32 bits, bits etc?




The registors are already in the right order, just send them.
 
Converting DINT's to INT's

Steve Bailey said:
A DINT uses two consecutive %R registers. If the values in the registers are all between -32768 and +32767, then the data is all in the first register (the one with the lower address). If the data is outside that range, then you need to send it as 32-bit data anyway.

The most straightforward way I've found to convert from INT to DINT is to first convert from INT to REAL, then from REAL to DINT.

I think you got it backwards. It's DINT's to INT's...I suppose I can go the same route, only backwards. The data is already scaled, 0-100 or 0-1000, for example. So there will be nothing below 0 or above, my guess right now, is 10,000.
 
I think you got it backwards. It's DINT's to INT's

The point is that if the value is between -32768 and +32767, then the value in the first register (lower address) is the same whether you use it in a function with data type DINT or INT. Within that range of values, you don't have to do anything to convert from DINT to INT.

If you need to convert from INT to DINT, when the value is greater than zero, all you need to do is make sure that the register with the higher address contains a value of zero. When the INT value is less than zero, you need to move a vlue of (hex)FFFF into the higher register to account for the sign bit.
 

Similar Topics

We just completed the conversion of a PLC 5/80 to a 1756-L8x processor. The old 5 program had numerous MSG instructions sending data to/from...
Replies
24
Views
9,480
Is there anyway to convert a BOOL to a INT (DINT or SINT) in ladder logic. I am working in RSLogix5000 and am attempting to count 4 Discrete...
Replies
3
Views
5,499
I have 3 values. DINT values. They make a product number when assembled together. D: DINT; L: DINT; H: DINT; The variables D, L and H are...
Replies
6
Views
6,630
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
208
Hello PLCs Forum, I am in a bit of a pickle and was hoping someone could offer me some help. I have a .rss file and just need to see the ladder...
Replies
2
Views
122
Back
Top Bottom