STL - Convert ASCII word to INT

JayD

Member
Join Date
Aug 2009
Location
Australia
Posts
53
Heya,

My current method is below but am certain there is a more efficient way.

Any ideas?

JD


L '23'
T #Test_ASCII_Word


L #Test_ASCII_Word
L W#16#FF00
AW
L #Test_ASCII_Word
TAK
-D
L B#16#30
-I
T #Tmp_Dec_Int


L #Test_ASCII_Word
SRD 8
L B#16#30
-I
L 10
*I
L #Tmp_Dec_Int
+I
T #Tmp_Dec_Int
 
Code:
      l     '23'
      l     '00'
      -i    
      push  
      aw    w#16#f
      tak   
      srw   4
      +i    
      bti

NB: I pasted this code in upper case yet it is now displayed in lower case.
 
Last edited:
Thanks both!

I had to simulate the code to figure it out. I was thrown by the BTI conversion (it is a hex to dec conversion), but now get it.

Cheers
JD
 
I need to also convert a DWord too.

Using your code structure I can extract the lowest and highest digit (as the wrong factor though), ie '1234' => 14 . Could you shed some light on this if you get anytime.

Many thanks in advance
JD

Code:
      L     '1234'
      L     '0000'
      -D                                //Determine hex difference to 0000
      PUSH                            //copy to ACCU1 to ACCU2
      AD    DW#16#F              //retrieve lowest digit in hex
      TAK                             //swap ACCU2 to ACCU1
      SRD   20                       //retrieve highest digit (as a factor of 10) in hex
      +I                               //add the two hex values
      BTI                              //convert hex to decimal
 
Last edited:
I figured out how to convert '1234' to W#16#1234 but now i don't think BTI will work as it now is over 3 digits.

Code:
      L     '1234'
      L     '0000'
      -D                              
      PUSH                          
      AD    DW#16#F            
      TAK                             
      AD    DW#16#F00          
      SRD   4                        
      +I                               
      T     #tmp_hex

      L     '1234'
      L     '0000'
      -D                                
      PUSH                            
      AD    DW#16#F0000        
      SRD   8                         
      L     #tmp_hex
      +I                                
      T     #tmp_hex


      L     '1234'
      L     '0000'
      -D                                
      PUSH                            
      AD    DW#16#F000000       
      SRD   12                          
      L     #tmp_hex
      +I
 
Use BTD instead if BTI

Code:
      L     '1234'
      L     '0000'
      -D    
      PUSH  
      AD    DW#16#F
      TAK   
      SRD   4
      +D    
      PUSH  
      AD    DW#16#FF
      TAK   
      SRD   4
      AD    DW#16#FFFFFF00
      +D    
      PUSH  
      AD    DW#16#FFF
      TAK   
      SRD   4
      AD    DW#16#FFFFF000
      +D    
      BTD
 
Last edited:
Thank you. I like the use of push and tak to store the data.

Is there any benefit in using this approach instead of storing the value in a word? I assume it may influence execution time.
 
There are a minimu of 2 accumulators (there are 4 in the S7-400 and 318). I just like to dust off some rarely used instructions now and again. There may be a small improvment in execution time but nothing to worry about unless you are calling the block many many times.
 

Similar Topics

Hi.Can I convert the block written in stl mode below to ladder mode? L #InOctet SLD 3 L #InBit OW T...
Replies
2
Views
549
i hope you could help me to convert the network Stl to lad it's apart from program of machine and i try to find solution for the reason of error...
Replies
10
Views
1,905
Hello everyone, I am migrating a program from STL to SCL via S7-1200 portal, I would like you to help me by converting these lines of code...
Replies
4
Views
1,617
Hi all, I'm currently trying to convert code written in STL for a S7-300 to SCL for an S7-1200. I'm getting stuck trying to address inputs in...
Replies
4
Views
2,636
I need some assistance to any Siemens Gurus' who can help me convert the following from STL to Lad. I have tried all the old tricks I can...
Replies
4
Views
4,289
Back
Top Bottom