TapHome

Data type conversions

TapHome script data type conversion functions — TODOUBLE, TOSTRING, TOBCD, FROMBCD, TOBYTEARRAY, RGBTOHSV, and HSVTORGB.

TODOUBLE

Converts string to number. Returns NaN on error.

TODOUBLE( text )

Examples:

TODOUBLE(“232”) ... 232)
TODOUBLE(“-192.332”)  ...  -192.332
TODOUBLE(“some text”)  ...  NaN

TOSTRING

Returns a string value of the specified value or Collection according to the specified encoding. Encoding is optional (iso-8859-1 is used by default).

TOSTRING(value, encoding)

Examples:

TOSTRING(192, “X”)  …  Result = “C0”
TOSTRING(192, “X4”)  …  Result = “00C0”
TOSTRING(192, “F4”)  …  Result = “123.3400”
TOSTRING(192, “F0”)  …  Result = “123”
TOSTRING(BYTECOLLECTION("48656c6c6f"))			(Result is “Hello”)
TOSTRING(BYTECOLLECTION(\"48656c6c6f\"), “iso-8859-1”)	(Result is “Hello”)
TOSTRING(192, “X4”)							(Result is “00C0”)

TOBCD

Converts the provided number to the binary-coded decimal (BCD) format. The scheme of encoding is BCD-8421.

TOBCD(number)

Examples:

TOBCD(1)  ...  1
TOBCD(9)  ...  9
TOBCD(10)  ...  16

FROMBCD

Decodes the provided number, that is encoded in binary-coded decimal (BCD) format. The scheme of encoding is BCD-8421.

FROMBCD(number)

Examples:

FROMBCD(16)  ...  10
FROMBCD(32)  ...  20

TOBYTEARRAY

Converts string to byte array according to the specified encoding. Encoding is optional (iso-8859-1 is used by default).

TOBYTEARRAY( string, encoding )

Examples:

TOBYTEARRAY("Hello")			(Result is byte array 48656c6c6f)

RGBTOHSV

Converts RGB color definition; returns color in Hue / Saturation / Brightness format.

RGBTOHSV( r, g, b )      (r, g, b ... 0 - 0xFF)

Example:

VAR HSVColor := RGBTOHSV( r, g, b );
VAR saturation := HSVColor.Saturation;   (Saturation ... 0 - 1)
VAR hue := HSVColor.Hue;                 (Hue ... 0 - 360)
VAR value := HSVColor.Value;             (Value ... 0 - 1)

HSVTORGB

Converts color defined by Hue / Saturation / Brightness; returns color in RGB format

HSVTORGB( hue, saturation, value )

Example:

VAR color := HSVTORGB( hue, saturation, 1)
VAR red := color.red;                   (red ... 0 - 0xFF)
VAR green := color.green;               (green ... 0 - 0xFF)
VAR blue := color.blue;                 (blue ... 0 - 0xFF)