
adccommunitymod (AutomationDirect) asked a question.
How to convert Hex to Decimal DL06
Created Date: September 29,2013
Created By: brine
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
Hello All Does anyone know a way to convert Hex to Decimal. I am sending data from a VB program to a FIND instruction and it is not "finding " because what I am sending is being read by the DL06 as Hex and the table being searched contains decimal values. I am sure there is a way to do it, and that someone knows. Brine
Created Date: September 29,2013
Created by: franji1
I'm guessing you mean BCD (e.g. what Timer/Counter accumulators use).
Your VB is sending 10 as 0x000A, but you need it to be 0x0010. Do
LD V2000 // where VB writes to
BCD
OUT V2001 // BCD equivalent of V2000
Or, as part of your FIND (if you don't need the BCD value for anything else), just add the BCD instruction AFTER the LD of the VALUE for the FIND instruction.
Created Date: October 03,2013
Created by: brine
Thanks for the reply
To clarify in VB I have declared the variable as Decimal. I am sending 3535 Decimal to the DL06. I need it to end up in the DL06 as 3535 Decimal.:D
Created Date: October 03,2013
Created by: brine
Thought I might share the solution that was found, although I do not know why it is working. If someone could enlighten me it would be appreciated.
The data being sent is by default read or converted to BCD by the DL06.
If I load V2407 (this is where VB is writing to) then insert a BCD instruction then OUT it to V2410 it then shows up as decimal.
This was found by experimentation, I have absolutely no idea why the BCD instruction is converting BCD to Decimal.
Is there an error in the instruction manual? It must be!:D
Created Date: October 03,2013
Created by: franji1
PCs do NOT use BCD, they use binary (aka decimal), and if signed, use 2's complement binary. The default numeric type in most of ADC's PLCs is BCD, so you must convert a decimal number to BCD if the source is decimal.
ADC's manual explains it very well in the BCD and BIN instruction sections of the Instruction chapter (they are correct :D).
Created Date: October 03,2013
Created by: bcarlton
Brine - it appears you are confused as to the nature of number storage in the PLC and the display of the numbers.
Refer to Appendix 'I ' in the DL06 manual for a discussion of number types and storage.
I have also written up my view of this subject
In short, the BCD and BIN commands do convert a number between the different storage types as indicated.
Created Date: September 29,2013
Created by: brine
Hello All
Does anyone know a way to convert Hex to Decimal. I am sending data from a VB program to a FIND instruction and it is not "finding " because what I am sending is being read by the DL06 as Hex and the table being searched contains decimal values.
I am sure there is a way to do it, and that someone knows.
Brine