Convert Hex

CvtToHex

The CvtToHex  procedure converts alphabetic characters to two-hex characters representing the top 4 bits and the bottom 4 bits of the character or byte.

hex-value   CvtToHex(
  szInChar        65535A   Const Varying 
)

See also: CvtFromHex ToUpper, ToLower

Parameters

szInChar
[input VChar(*) const]  A varying or fixed-length character value whose length is 1 to 65535. The characters in this parameter are converted to two hexadecimal character. That is, the number '1' is converted to 'F1'.

Return Value

If the function succeeds, the return value is the hexadecimal value of the characters from the szInChar parameter.

Example

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++++++++++
     D myData          S             50A   Inz('12345')
     D myHex           S            100A   
 
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++

     C                   callp     myHex = CvtToHex(%trimR(myData))

Remarks

This procedure uses a high-speed, low-level MI instruction.

Note the user of the %trimr() built-in. With out this built-in , the procedure would have also converted the trailing blanks in the 50-position myData field.


CvtFromHex

The CvtFromHex  procedure converts a string containing two-hex characters to a string containing characters whose bytes are composed from the pairs of characters.

char-value   CvtFromHex(
  szInHexValue        65535A   Const Varying 
)

See also: CvtToHex ToUpper, ToLower

Parameters

szInHexValue
[input VChar(*) const]  A varying or fixed-length character value whose length is 1 to 65535. Each pair of characters in this parameter are "compressed" to form a single character.

Return Value

If the function succeeds, the return value is the character version of the hex characters passed to the first parameter.

Example

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++++++++++
     D myData          S             50A 
 
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++

     C                   callp     myData = CvtFromHex('F1F2F3F4')

After the CvtFromHex is called, the myData field will contain the character string '1234'.

Remarks

This procedure uses a high-speed, low-level MI instruction.