converting hex to decimal

Steve,

ever thought of simply moving (copying) the hex variable to a variable defined as integer?

Regards,
 
Windows Calculator.

You aren't looking to 'convert' a number, you are looking to change the representation of a value stored in a computer.
10 (base 10, decimal) is equal to 0A (base 16, hexadecimal) is equal to 12 (base 8, octal) is equal to 1010 (base 2, binary).

For that matter, it's also equal to 101 (base 3, trinary?) or 022 (base 4, quarnary?).
 
Why do you need this, which s7 plc is it for ? and what is your step 7 experience ? The reason I ask is that the implementation can be completely generalised and use pointers, or it can be simple and only work for a well defined set of circumstances. Give us a clue as to which way to go !
 
The PLC is a siemens cpu 314.

My experience is limited and the application which I need the conversion software is as follows;

WE have a SCA gluing application which sends quantity data in the form of hexidecimal to our siemens PLC which inturn sends the data to our server as we need to keep gluing quantities for our records.

The SCA cannot convert from hex from there side and was hoping to convert the data in the PLC.
Is there a simple way???

Thanks for your help.
 
As rdrast said above, if what you are receiving in the PLC is actually a number, then its format (hex, decimal, etc.) is irrelevant - the value is the same regardless of the display format.

If, on the other hand, what is actually being sent to the PLC is a text String (usually displayed in hex) representing the number, then you need to convert this String to a number using the IEC functions available in the Standard Library.

If you aren't sure what form the data is coming in, have a look at where it's being stored in the PLC. If it's in several Bytes in a DB for example, then it's probably a String.

If you can identify where the data is being stored and display the data in a VAT (preferably Byte for Byte) and post a screen dump of this display, we'll probably be able to identify the data and help you from there.
 
Windows Calculator.

You aren't looking to 'convert' a number, you are looking to change the representation of a value stored in a computer.
10 (base 10, decimal) is equal to 0A (base 16, hexadecimal) is equal to 12 (base 8, octal) is equal to 1010 (base 2, binary).

For that matter, it's also equal to 101 (base 3, trinary?) or 022 (base 4, quarnary?).

I know its an old thread, but it gives me the opportunity for these:-

I bought a book the other day - "1001 Interesting facts about Binary" I took it back as there was only 9 things in it.

There are 10 types of people in the world, those that understand binary, and those that don't.
 
A step7 source. conversion of hex to decimal.

FUNCTION "Function_Hex_to_Dec" : VOID
TITLE =
//Hex to decimal conversion
//-------------------------
//Designed by: Kevin Bloch
//BlochTechnologies Australia Pty Ltd
//www.blochtech.com
VERSION : 0.1

VAR_INPUT
In_Hex : INT ;
END_VAR
VAR_OUTPUT
Out_Dec : INT ;
END_VAR
VAR_TEMP
DI_Temp1 : DINT ;
R_Temp1 : REAL ;
R_Temp2 : REAL ;
DI_Temp2 : DINT ;
R_Temp3 : REAL ;
R_Remainder1 : REAL ;
R_Remainder2 : REAL ;
R_Remainder3 : REAL ;
R_Remainder4 : REAL ;
R_Remainder5 : REAL ;
T_Real10 : REAL ;
T_FinalValue : REAL ;
END_VAR
BEGIN
NETWORK
TITLE =
A( ;
L #In_Hex;
ITD ;
T #DI_Temp1;
SET ;
SAVE ;
CLR ;
A BR;
) ;
JNB _001;
L #DI_Temp1;
DTR ;
T #R_Temp1;
_001: NOP 0;
NETWORK
TITLE =
A( ;
A( ;
L #R_Temp1;
L 1.600000e+001;
/R ;
T #R_Temp2;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _002;
L #R_Temp2;
TRUNC ;
T #DI_Temp2;
AN OV;
SAVE ;
CLR ;
_002: A BR;
) ;
JNB _003;
L #DI_Temp2;
DTR ;
T #R_Temp3;
_003: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Temp2;
L #R_Temp3;
-R ;
T #R_Remainder1;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _004;
L #R_Remainder1;
L 1.600000e+001;
*R ;
T #R_Remainder1;
_004: NOP 0;
NETWORK
TITLE =
NETWORK
TITLE =
A( ;
A( ;
L #R_Temp3;
L 1.600000e+001;
/R ;
T #R_Temp2;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _005;
L #R_Temp2;
TRUNC ;
T #DI_Temp2;
AN OV;
SAVE ;
CLR ;
_005: A BR;
) ;
JNB _006;
L #DI_Temp2;
DTR ;
T #R_Temp3;
_006: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Temp2;
L #R_Temp3;
-R ;
T #R_Remainder2;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _007;
L #R_Remainder2;
L 1.600000e+001;
*R ;
T #R_Remainder2;
_007: NOP 0;
NETWORK
TITLE =
NETWORK
TITLE =
A( ;
A( ;
L #R_Temp3;
L 1.600000e+001;
/R ;
T #R_Temp2;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _008;
L #R_Temp2;
TRUNC ;
T #DI_Temp2;
AN OV;
SAVE ;
CLR ;
_008: A BR;
) ;
JNB _009;
L #DI_Temp2;
DTR ;
T #R_Temp3;
_009: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Temp2;
L #R_Temp3;
-R ;
T #R_Remainder3;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _00a;
L #R_Remainder3;
L 1.600000e+001;
*R ;
T #R_Remainder3;
_00a: NOP 0;
NETWORK
TITLE =
NETWORK
TITLE =
A( ;
A( ;
L #R_Temp3;
L 1.600000e+001;
/R ;
T #R_Temp2;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _00b;
L #R_Temp2;
TRUNC ;
T #DI_Temp2;
AN OV;
SAVE ;
CLR ;
_00b: A BR;
) ;
JNB _00c;
L #DI_Temp2;
DTR ;
T #R_Temp3;
_00c: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Temp2;
L #R_Temp3;
-R ;
T #R_Remainder4;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _00d;
L #R_Remainder4;
L 1.600000e+001;
*R ;
T #R_Remainder4;
_00d: NOP 0;
NETWORK
TITLE =
NETWORK
TITLE =
A( ;
A( ;
L #R_Temp3;
L 1.600000e+001;
/R ;
T #R_Temp2;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _00e;
L #R_Temp2;
TRUNC ;
T #DI_Temp2;
AN OV;
SAVE ;
CLR ;
_00e: A BR;
) ;
JNB _00f;
L #DI_Temp2;
DTR ;
T #R_Temp3;
_00f: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Temp2;
L #R_Temp3;
-R ;
T #R_Remainder5;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _010;
L #R_Remainder5;
L 1.600000e+001;
*R ;
T #R_Remainder5;
_010: NOP 0;
NETWORK
TITLE =
NETWORK
TITLE =
L #R_Remainder1;
T #T_FinalValue;
NOP 0;
NETWORK
TITLE =
A( ;
L #R_Remainder2;
L 1.000000e+001;
*R ;
T #T_Real10;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _011;
L #T_FinalValue;
L #T_Real10;
+R ;
T #T_FinalValue;
_011: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Remainder3;
L 1.000000e+002;
*R ;
T #T_Real10;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _012;
L #T_FinalValue;
L #T_Real10;
+R ;
T #T_FinalValue;
_012: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Remainder4;
L 1.000000e+003;
*R ;
T #T_Real10;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _013;
L #T_FinalValue;
L #T_Real10;
+R ;
T #T_FinalValue;
_013: NOP 0;
NETWORK
TITLE =
A( ;
L #R_Remainder5;
L 1.000000e+004;
*R ;
T #T_Real10;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _014;
L #T_FinalValue;
L #T_Real10;
+R ;
T #T_FinalValue;
_014: NOP 0;
NETWORK
TITLE =
A( ;
L #T_FinalValue;
TRUNC ;
T #DI_Temp1;
AN OV;
SAVE ;
CLR ;
A BR;
) ;
JNB _015;
L #DI_Temp1;
T #Out_Dec;
_015: NOP 0;
END_FUNCTION


Please test this first as I only ran a quick simulation to make sure it works...
 

Similar Topics

Can I convert a decimal nubmer to HEX in step 7,and if it is,would you please guide me through it(wich function tu use,and so on...) I have to...
Replies
3
Views
6,922
I have a 3-axis sensor that I'm working on integrating with a Micrologic PLC. The sensor has a RS-422 output and I'm using an RTA Automation PLC...
Replies
5
Views
3,191
Hello Once again, Anyone have a method of converting a decimal Value in Decimal to Hexadecimal in ladder logic, PLC i'm using is Logix 5000.
Replies
27
Views
17,740
My OPC server has a string value of "401-534" which I would like to have apperar on my Horner Lx280 PLC touchscreen. I have 10 16 bit registers...
Replies
1
Views
2,211
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
175
Back
Top Bottom