Jump to content

Recommended Posts

Posted

Hi,

I'm trying to convert a binary string format to integer using Q03UDE CPU.

String data : '1001'

Expected Result :  9

Kindly help.

 

 


Posted

You don't have to do anything. This is just interpretation of data.

De word device containing the data will look like when monitoring in Binary format 0000.0000.0000.1001

If you monitor Dec in you will see 9
If you monitor Hex in you will see 9

If it is string data then you can use STR_TO_INT

Posted

Hi,

I have a string variable named stringData with a value of '1001' binary format.. I want to convert it to a decimal value of 9 . I found a solution for this using some manipulation.. however, I am wondering if there's a direct conversion for this..

please check the attached image.. I am using ST program.

code.png

Posted

You should explain a bit more why and what you are doing. Plus, that line of code explains nothing except the fact that your are using a string in almost "binary" format what you want to convert. There are no logical reasons (the way I see it) why you would ever interpret stringdata 1001 into decimal 9...

How did you get stringdata 1001? What are you going to do with it? Why do you need it converted? What's the purpose?

Posted

i agree, using string to represent numeric values is less than ideal.

but if that's what you have, use a loop and go through each string character,

something like this (sample pseudo code):


INT N, I
N:=0
FOR I:=1 to stringData.LEN
  N:=N+N
  if stringData[I]=='1' then 
     N:=N+1
  endif
NEXT

 

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
×
×
  • Create New...