SLC500 - need to convert FP to integer

James Fillmore

Lifetime Supporting Member
Join Date
Sep 2004
Location
Detroit, MI
Posts
45
Need to convert a floating point register thats the total of "seconds since midnight" (would only be like 84,000 max) to integers so I can then do an integer to string conversion and print on a barcode label. I do know how to concantenate (SP?) the strings so if I could take say 82,550 and turn it into 2 integers, 82 and 550 that would be ideal.

Thanks!
 
Multiply by .001, subtract .50 and put the result in an integer. The SLC automatically rounds when converting a float to an integer, so subtracting .5 makes the rounding work in your favor. Now multiply the integer by 1000.0 (note that 1000.0 is a float, not an integer), subtract it from the original float, and put that result in the second integer.

F8:0 = 82550
CPT N7:0 (F8:0*.001)-0.5) <-N7:0 = 82
CPT N7:1 (F8:0-(N7:0*1000.0) <-N7:1 = 550

But I have to ask, when computing seconds from midnight why use a float in the first place, why not start with two integers?
 
Last edited:
I spent the last hour reading over MANY posts and have found no simple solution to this question. AB's knowledge base has a very simplistics version on converting 999.999 to 2 integers that hold 999 and the fractional 999.

But to take a large floating point number (thats greater that the 32,??? thats greater an N7 word can hold) and convert that to 2 integer to be used for HMI display, or in my case converting to strings and printing, doesn't appear to be an easy task.

AB's COP instructing (I'm using a 5/03) lets me COP F8:0 to N7:0 and N7:1. But when I put say 33000 in F8:0 I get 18176 in N7:0 and -6144 in N7:1. How to I convert THOSE to nmbers that mean something?

I'd like N7:0 to contain 33 and N7:1 to contain 000. Ideally 2 groups of digit that represet xxx (greater than 1000) and xxx (less than 1000)

If I do a simplistic divide by 1000 to a large value like 83545 and put the answer in a N (integer) word I get 84. Is there some obvious method that I'm overlooking to prevent it from rounding? If there was then I would have the upper digits (greater than 1000). I could then multiply this answer by 1000 suptract it from the original floating point value and get the lower 3 digits (less than 1000). Seems easy enough. What am I missing/doing wrong?
 
James Fillmore said:
AB's COP instructing (I'm using a 5/03) lets me COP F8:0 to N7:0 and N7:1. But when I put say 33000 in F8:0 I get 18176 in N7:0 and -6144 in N7:1. How to I convert THOSE to nmbers that mean something?

Those numbers do mean somthing - they are the bit pattern of a 32 bit IEEE-754 floating point number. But when you try to display it using a decimal radix for integers, the computer interprets them as two 16 bit integers instead. I've covered working direcly with floats in several posts, but thats not what is necessary here. See my previous post.
 
Alaric already answered your real question (quite well by the way) so I'll leave that alone.


The COP command performs a byte for byte copy from the source to the destination. The floating point number is an IEEE 754 floating point number. They byte-for-byte copy will leave you with integers that contain what appear to be garbage but are in fact the original bytes from the float.

Keith
 

Similar Topics

Hello im hoping someone can point me in the right direction. I have a SLC-500 that the program has been erased. I'm being told it will require an...
Replies
3
Views
1,515
I have a test rack setup but dont have all of the I/O cards. Im trying to figure out how to make it quit going into a major fault because of a...
Replies
1
Views
1,649
Hi! I new to the SLC500, I know not thing about Allen Bradley PLC. But where I'm work we have the machine it has th SLC500 and first the tow of...
Replies
9
Views
5,386
I am having a problem getting the jmp and lbl logic to work in my program. I have attatched a copy of the program and would appreciate it if...
Replies
22
Views
10,031
Guest
G
can the slc500 5/05 send a email and text over Ethernet ?
Replies
3
Views
149
Back
Top Bottom