Sign in to follow this  
Followers 0
Delt

Dec To Hex Conversion

3 posts in this topic

somebody know if there are some instruction or short method in RsLogix500 to convert DEC to HEX and pass it to ST file e.g. (N7) 123d ---> 7Bh (ST) or i need to apply the typical algorism in lader logix operation by operation? DIVISION / RESULT / REMAINDER (in HEX) 123 / 16______7_____(0.6875)(16)=11=B 7 / 16________0_____(0.4375)(16)=7 ANSWER 7B Thanks

Share this post


Link to post
Share on other sites
I'm not 100% sure what you are asking. You want to convert a value in N7 into a Hexadecimal string. Is the value in N7 'normal' or is it binary coded decimal (BCD)? Does this mean you only want to convert into 4 Hexadecimal digits (the maximum value in 16 bits) What about negative numbers - are they treated as positive? There are 4 instructions which may be of use to you (probably not though) TOD which converts a 16bit value to a 16bit binary coded decimal value (BCD) FRD which does the opposite of above AIC which converts a 16bit value into a decimal string and ACI which does the opposite.

Share this post


Link to post
Share on other sites
It's not the most pretty code but this converts where N7:0=123 to ST9:0="7B" and uses N7:1 and N7:2 as temp stores. SOR BST AND N7:0 15 N7:1 NXB ADD N7:1 48 N7:1 NXB GEQ N7:1 58 ADD N7:1 7 N7:1 BND EOR SOR BST AND N7:0 240 N7:2 NXB DIV N7:2 16 N7:2 NXB ADD N7:2 48 N7:2 NXB GEQ N7:2 58 ADD N7:2 7 N7:2 BND EOR SOR BST SWP #N7:2 1 NXB OR N7:1 N7:2 N7:1 NXB MOV N7:1 ST9:0.DATA[0] NXB MOV 2 ST9:0.LEN BND EOR converts the lower byte (0-255) from N7:0 to a 2 digit hex value in ST9:0 (with trailing zero). If you repeat the code after a SWP instruction to swap the high byte of N7:0 to the low byte you can acheive a 4 digit hex value (16 bits) and if your N7:0 is BCD then do an FRD instruction at the start. Hope this helps (although it may hurt) Edited by Spedley

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
Sign in to follow this  
Followers 0