Decimal to ASCII-Hex

Last Updated 2 years ago

 

ASCII-Hex is a 2-character representation (2 byte) of a hex value. Where a carriage return is a single byte in hex (0x0d), ASCII-Hex would be "0D" (0x0d 0x44).

In this example, Onkyo uses ASCII-HEX for volume level. The syntax is:

!1MVLXX ("XX" = ASCII-Hex Value, Range 00-C8, or 0-200 decimal).

A slider is used in YIPI for the volume, setting the numeric variable nOnkVol to 0-200.

In WOWE we use some formulas and conditional actions to build the ASCII-Hex, detecting 0-9 and A-F, and setting these values into string variable sAscHex:

Find numeric MSB: CHAR((nOnkVol / 16) + 48)

Find alpha MSB: CHAR((nOnkVol / 16) + 55)

Find/append numeric LSB: sAscHex + CHAR(mod(nOnkVol,16) + 48)

Find/append alpha LSB: sAscHex + CHAR(mod(nOnkVol,16) + 55)

The resulting ASCII-Hex value is passed to string variable sOnkVol, and used in the command:

"!1MVL" + sOnkVol + "%0d"

File.php

Note:

Download the attached, and rename, dropping the ".txt" extension.

 

Originally published 1/11/2018