← Strings and Text

Hex Text to Number

hard

Reads a number a device sends as hex text, such as 'A1C8', and rejects text that is not hex.

What it teaches

A character is stored as its code: '0' is 48, '9' is 57, 'A' is 65 and 'a' is 97. Each digit is worth what it was in Byte to Hex Text, 0 to 15, with 'a' to 'f' worth the same as 'A' to 'F', so 'A' is 10, not 0. Each place is worth 16 times the place to its right, so '10' is 16 and '1F' is 1 × 16 + 15 = 31. One to four hex digits are valid; any other character, such as the G in '12G4', is not. STOD cannot help, because it reads decimal only.

Parameters

TagDirectionTypeDefaultDescription
Out_ValueOutputDINT0The number Ref_Hex spells, or 0
Sts_ValidOutputBOOL0Ref_Hex is 1 to 4 hex digits
Ref_HexInOutSTRING—Hex digits as a device sends them

Required behavior