DWORD_TO_HEXSTR

DWORD_TO_HEXSTR 1:

This function converts a decimal number into a hexadecimal string (base 16).

FUNCTION DWORD_TO_HEXSTR : T_MaxString

T_MaxString

VAR_INPUT
    in          : DWORD;
    iPrecision  : INT;
    bLoCase     : BOOL;
END_VAR

in: The decimal number requiring conversion.

iPrecision: Minimum number of displayed digits (digits). If the actual number of significant digits is less than the iPrecision parameter, the resulting string is filled with zeros from the left. If the number of significant digits is greater than the iPrecision parameter, the resulting string is not cut off! If the iPrecision parameter and the in parameter are zero, the resulting string is empty.

bLoCase: This parameter determines whether lower- or upper-case letters are used in the conversion. FALSE => "ABCDEF", TRUE => "abcdef".

 

Example in ST:

PROGRAM MAIN
VAR
    s1      : STRING;
    s2      : STRING;
    s3      : STRING;
    s4      : STRING;
    nCnt    : WORD;
END_VAR
nCnt := 43981;
s1 := DWORD_TO_HEXSTR( nCnt, 1, FALSE );
s2 := DWORD_TO_HEXSTR( nCnt, 1, TRUE );
nCnt := 15;
s3 := DWORD_TO_HEXSTR(  nCnt, 4, FALSE );
nCnt := 0;
s4 := DWORD_TO_HEXSTR( nCnt, 0, FALSE );

The result:

s1 = 'ABCD'

s2 = 'abcd'

s3 = '000F'

s4 = ''

 

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT v2.9.0 Build >1021

PC or CX (x86)

TcUtilities.Lib

( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically )

TwinCAT v2.10.0 Build >= 1301

CX (ARM)