#8 Find or create a Codesys solution for: LWORD_TO_HEXSTR

v1.0
closed
nobody
None
2020-05-01
2019-05-04
aliazzz
No

This function converts a decimal number into a hexadecimal string (base 16).
FUNCTION LWORD_TO_HEXSTR: T_MaxString
VAR_INPUT

VAR_INPUT
    in          : LWORD;
    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:

PROGRAM MAIN
VAR
    s1   : STRING;
    s2   : STRING;
    s3   : STRING;
    s4   : STRING;
    nCnt : LWORD;
END_VAR

nCnt := 43981;
s1   := LWORD_TO_HEXSTR( nCnt, 1, FALSE );
s2   := LWORD_TO_HEXSTR( nCnt, 1, TRUE );
nCnt := 15;
s3   := LWORD_TO_HEXSTR( nCnt, 4, FALSE );
nCnt := 0;
s4   := LWORD_TO_HEXSTR( nCnt, 0, FALSE );

The result:

s1 = 'ABCD'

s2 = 'abcd'

s3 = '000F'

s4 = ''

Discussion

  • aliazzz

    aliazzz - 2019-05-05

    Ticket moved from /prj/tcunit4codesys/tickets/11/

     
  • aliazzz

    aliazzz - 2019-05-05

    Ticket moved from /prj/csunit/tickets/8/

     
  • zer0g - 2019-05-07

    See comment from BYTE_TO_HEXSTR.

     
  • aliazzz

    aliazzz - 2019-05-08
    • status: open --> closed
     

Log in to post a comment.