RS logix 5000

For float to int just use a move (MOV) instruction (with source as the float and an integer as the destination). Not sure about HEX dont have logix in front of me to check either.
 
The instruction MOV will copy the whole number portion of a float to an INT or DINT (or even BYTE) type, as far as it can be represented. The fractional portion will be lost.

INT and HEX are different things entirely. INT is a data type, HEX is a numeric representation, specifically base 16. In any simple binary form (not encoded as Floating point, or BCD), the representation is purely for convenience. There is no difference at all between:
00001010b (binary)
0x0A (hex)
10 (decimal)
012 (octal)
or, for that matter, even
101 (base 3).

If you are communicating between devices, and need to maintain the 32 bit representation of the floating point number, you can COPy it into two consecutive integers, and send to a device. Assuming there are no endian problems.
 
THERE IS NO FORMULA TO CONVERT FLOATING POINT TO HEX...
Unless you want to break out each individual field of the 32 bit IEEE Floating point format.

Just MOV your value.

MOV MyFloat MyInt

Done.
It is just truncated. Integral (not just Integer, but IntegRAL) numeric formats cannot store decimal points.

To simulate it, you can try using a scaled fixed point format.

MUL MyFloat 1000 MyDINTValue
 
Now I am curious.

Why would you ever want to put a float into HEX? (which is impossible, as rdrast said)

You must have a reason, but I am at a loss as to what it may be!

Give some details and maybe a solution to your problem will be found.
 
Help us out here because there is an obvious lack of communication going on here.


Assuming you have a floating point number 123.456

Do you want to get the hex value 0x42F6E978 or do you want to get the hex value 0x7B? There are instructions (MOV and COP) that will do both, but you need to communicate what you want.
 
Last edited:
i am having two Hex registers

1st Register value is F241
2nd register value is 47dc

The value in the device is 113124.5078

My actual need is to get the floating point variable from the 2 Hex register values. How to read the value 113124.5078 in the PLC.
 
You have two values. You have expressed their individual values in hex as F241 and 47DC. You have stated that their floating point value is 113124.5078.

The two registers you refer to are each 16 bit registers. A float value is usually stored in a single 32 bit representation.

Our first test is, do the two register value actually represent the floating point value in some way? With a little help from this site we can see that they are equivalent if the two 16 bit registers are arranged in this manner: 47DCF241

Another cheat is to use this companion site, type in the two 4 digit hex numbers in the correct order and out pops a floating point value, 113124.51. Well that's not exactly the same but close.

Now, if the two hex values are placed into two two INT registers, lets say hexint[0] which gets '47DC' and hexint[1] which gets 'F241', then the COPy command can be used with a source of hexint[0] and a destination of a real tag (let's call it 'myreal') with a length of 1 (there's only 1 real tag as the target) then 'myreal' can now be read as the floating point number.
 
I am not sure how we can make it any more clear than what has already been explained to you.

Open the attached program and see how it is done (you need Logix5000 Version 16 or higher). Look at the tags and note their data type and contents. If you don't understand that then I am not sure what more we can do to help you. I strongly recommend that you take the time to learn how floating point numbers are represented in computers and that in the computer there is no difference between hex, binary, and decimal, they are all exactly the same same bit pattern in memory. Radix matters only to us Humans.

In addition to the links Bernie already gave you, see these articles:
http://en.wikipedia.org/wiki/IEEE_754-1985
http://en.wikipedia.org/wiki/Endian
http://en.wikipedia.org/wiki/Radix
 

Similar Topics

Hi folks, in the alarm manager of Rslogix 5000, the tag-based alarm has been created. But when I tried to change the condition, it was found the...
Replies
2
Views
140
I am completely stuck on building a ladder program that requires a start button to be pressed 3 times to turn on motor 1. Then motor 2 starts...
Replies
20
Views
568
Is there a way to use the FAL instruction to do +=2 instead of +=1? I have an array that is organized with alternating "data" and "flag" values...
Replies
5
Views
125
I have an AOI with revision notes. Someone entered the last note into the description instead of the notes. I cannot just click into the revision...
Replies
4
Views
148
Back
Top Bottom