samwf

convert Converting ASCII to Real to DINT

2 posts in this topic

I am new at PLC programming, I have tried some ways to convert a text into DINT and I haven't found the right way yet, maybe somebody can help me. I want to convert "Hello" to DINT, for example. I tried converting it on here  https://www.branah.com/ascii-converter  to decimal and then using it as an input for a ROUND, FLOOR, TRUNC blocks to get a DINT, but when I get the result and use as an input in a DI_R i block the output doesn't match with the first conversion of "Hello".

Any tips on how do I get it to work, please? Thanks in advance. 

Share this post


Link to post
Share on other sites

First of all, that website is not converting the ASCII to decimal the way you think.  It is simply converting each character to an INT and cramming it together.

The result of "Hello" is like this:

H = 0x48 = 072 DEC

e = 0x65 = 101 DEC

l = 0x6c = 108 DEC

l = 0x6c = 108 DEC

o = 0x6f = 111 DEC

So the value 072101108108111 (072 101 108 108 111) is just the decimal values of each character side by side with no spaces.  The whole value of "Hello" would really be 310,939,249,775‬, which is too big for a DINT (DINT has a maximum value of  2,147,483,648).  Open Windows Calculator, switch to Programmer, switch to HEX, and type in 48656C6C6F, and you'll see the decimal value

 

 

ASCII-HEX-DEC.png

WindowsCalculator-HEX.png

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