Posted 13 Jun 2017 Hi, I'm trying to convert a binary string format to integer using Q03UDE CPU. String data : '1001' Expected Result : 9 Kindly help. Share this post Link to post Share on other sites
Posted 13 Jun 2017 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 Share this post Link to post Share on other sites
Posted 13 Jun 2017 Hi Gambit, I tried STR_TO_INT function, however the result is '10100'. Share this post Link to post Share on other sites
Posted 13 Jun 2017 I am confused now. Do you have a String (ascii) value or Binary? Share this post Link to post Share on other sites
Posted 17 Jun 2017 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. Share this post Link to post Share on other sites
Posted 17 Jun 2017 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? Share this post Link to post Share on other sites
Posted 18 Jun 2017 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 Share this post Link to post Share on other sites