Converting Large Integer to Ascii String Characters

Cfordit

Member
Join Date
May 2011
Location
Cleveland
Posts
6
Is there a way to convert these integers (17476,16688,13110,12598) to Ascii character (DDA03616)?

17476 = 4444hex = DD on ascii chart
16688 = 4130hex = A0 on ascii chart
13110 = 3336hex = 36 on ascii chart
12598 = 3136hex = 16 on ascii chart

We are using a Allen Bradley PLC5.

Thanks for any responses.
 
If you only mean these particular 4 numbers then you have already done it.

But take something like 6143. That produces hex 17FF. 17 is the ETB control character. FF is not defined in normal ASCII (though it may be in various 'extended ASCII' tables). What would you want in those cases?

Are you limiting this to integers whose hex representation result in printable characters? Possibly only characters in the 'hex' character set (0 - 9, A - F)?
 
If I understand you correctly, I'm assuming you have a device that returns a string, DDA03616 for example, and puts that information in to four consecutive integer registers. What the code pictured below does is break the first integer into two eight bit pieces, or the first two characters.

The first rung masks and extracts the upper 8 bits (the first ASCII character) and places them in A9:0. The second rung masks and extracts the lower 8 bits (the next ASCII character) and places them at A9:1. These bits make the binary value for the ASCII character.

I've only shown one integer. I hope that helps.

(I haven't tested this to see if it works)

TC012320131.JPG
 
Last edited:
A little more information on what you are trying to do would be helpful. Your original question about converting Integers to Ascii characters isn't very feasible. As Bernie pointed out, you can't represent *any* Integer as two Ascii characters like your examples. If you stick to 0-9, A-Z even using lowercase you only have 3844 possible combinations, that's about 10% of the range of a 16bit Integer.

However, an important point here is that "17476 = 4444hex = DD on ascii chart" are all exactly the same bit pattern so there really isn't any conversion required.

So what are you trying to accomplish?
 
OK, this turned out to be ridiculously easy once I got a chance to jump online with a PLC/5 and actually test it.

If my original assumption (you know how assumptions go) was correct that you have a string that is stored in 4 consecutive integers and you want to turn this into a string, then just move the integers to the string and set the string .LEN to 8.

I've tested this and it works. The attached screen show shows the rung under test and the data tables. I used the four integers from your first post and a string destination.

TC012320132.jpg
 
Last edited:

Similar Topics

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
211
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
125
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
331
Hello, did anybody know, if there exist an converting cable like the1492-CM1746-M01 (for an 1746-IB16 to an 5069-IB16), for an 1746-HSCE to an...
Replies
3
Views
393
Hello, This will be my first time converting powerflex 40's and 400's from devicenet to ethernet. I did some research, and it seems I will need...
Replies
4
Views
760
Back
Top Bottom