Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter FiveGeneral Functions (continued)

HexToInteger Function

Overview

The HexToInteger function converts a string to a 64-bit qword.

Syntax/Parameters

Syntax

qword = HexToInteger ( string data | wstring data );

Parameters

data

A string or wstring in hexadecimal format with an optional leading ‘0x’ prefix.

Return Value

Returns a qword value representing the hex data or 0 on failure. Use the GetLastError function to retrieve error information.

Remarks

The string can be in plain hexadecimal format or lead with the prefix ‘0x’. It can also be a single 4-bit nybble to a full 64-bit value. It cannot contain any characters other than the hex value or prefix. Because 0x000000000000000 can be a valid return value, use the GetLastError function to determine if an error occurred (likely ERROR_SYNTAX or ERROR_OVERFLOW).

While the return value type is a qword, the result can be placed into any type with the recognition that the value may be truncated. Since hexadecimal representations of values are not signed, it is up to the script to manage negative numbers and sign extension. For example:

int i;

i1 = HexToInteger("0xFFFFFFFF");

MessageBox('I', "Result: %d", i); 

Will not result in -1 but rather 4294967295. To extend the sign:

int i;

i = HexToInteger("0xFFFFFFFF");

if ((i & 0x80000000) != 0) {

  i |= 0xFFFFFFFF00000000;

  }

MessageBox('I', "Result: %d", i);

This assumes a 32-bit signed value is expected. When the 32nd bit is set, the sign is extended. Note that Legato uses 64-bit math internally and if a signed value is placed into a smaller container, i.e. long to int, the extra sign bits are stripped. Therefore, if a long type is used, this procedure is not necessary. Further, if the hex value is not expected to be signed, the procedure is not required.

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Legato IDE, Legato Basic