Sign in to follow this  
Followers 0
Lotus

transfer float to 2 int

3 posts in this topic

Hello I have a float (32bit) containing a variable, and i need it sent via DeviceNet so i need it to be split up into 2 integers(16 bit). I just dont know how, i tried to use COP to 2 integers, but the result didnt make any sense to me. The float variable could be something like this: 12340.3512 but the decimal numbers are not important (at least for now) The max float value is close to 460,000

Share this post


Link to post
Share on other sites
In an IEEE754 floating point number the first bit is the sign bit, the next 8 are the exponent, and the remaining 23 bits are the mantissa. When you do a COP or CPW you make a bit for bit copy of the contents of the float. This is why the integer values in the 16 bit words don't seem to make sense to you. Here is a tool that allows you to see what the bit patern of a floating point number is: http://babbage.cs.qc.edu/IEEE-754/Decimal.html Take a look at http://www.wikipedia.org/search-redirect.p...%3E++&go=Go for more information. Also, see AB technote 18209 in the AB knowlegebase at http://www.rockwellautomation.com/knowledgebase/ Copying your max value, 460000.0 into two consecutive integer words should yield the integer value of 18656 in the first word and -25600 in the second word. Edit to add: Also, do a search on this forum. We have discussed several applications where instruments on an IO buss produce/consume floating point data as two or four integer words. Many of these posts have program examples included in them and some have even been linked to from Allen Bradley's knowledge base. Edited by Alaric

Share this post


Link to post
Share on other sites
the result wont make sense to you because of what alaric specified. it should work with what you did.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0