Hex To Dec

In a response on the dirGames-L thread “about sending data to html with webXtra”, Valentin Schmidt mentions that in his estimate, the fastest Lingo method of converting decimal values to hexadecimal is through the use of the rgb color object and its hexString method. The reverse is also useful.

As an example, take the hexadecimal value D7. To identify its decimal equivalent:

h = "D7"
hx = "#" & h & "0000"
put hx
-- "#D70000"
c = rgb (hx)
put c
-- color( 215, 0, 0 )
put c.red
-- 215

215 in decimal notation, of course, equals D7 in hexadecimal.

Going the other direction, if you wanted to convert a number from decimal to hexadecimal:

d = 186
c = rgb (d, 0, 0)
put c.hexString ()
-- "#BA0000"
put c.hexString ().char[2..3]
-- "BA"

So simple!