Ted Sullivan has previously posted a nice LUA script for converting decimal number to hex:
I wonder, is it possible to use the LUA string library to do the opposite conversion? I couldn't find the answer by searching the Net.Code:function Dec2Hex(nValue) if type(nValue) == "string" then nValue = String.ToNumber(nValue); end nHexVal = string.format("%X", nValue); -- %X returns uppercase hex, %x gives lowercase letters sHexVal = nHexVal..""; return sHexVal; end
I needed a solution and consequently I wrote my own script. In case any of you should need it:
Why I needed it? I was about to test the language code in MS Office (Hi, SUF6NEWBIE). A Registry call returns decimal values like 1033 (English). I put the MS codes into a table and could use this actionCode:function Hex2Dec(sValue) bFigErr = false; if type(sValue) == "number" then sValue = sValue..""; end sValue = String.TrimLeft(sValue, "0"); nDigits = String.Length(sValue); nTotal = 0; -- 414 = 4*16^2 + 1*16^1 + 4*16^0 power = base^exp while nDigits > 0 do sIn = String.Upper(String.Left(sValue, 1)); if sIn > "9" then if sIn == "A" then nFactor = 10; elseif sIn == "B" then nFactor = 11; elseif sIn == "C" then nFactor = 12; elseif sIn == "D" then nFactor = 13; elseif sIn == "E" then nFactor = 14; elseif sIn == "F" then nFactor = 15; else -- error bFigErr = true; sTotal = ""; break; end else nFactor = String.ToNumber(sIn); end -- go nTotal = nTotal + nFactor * Math.Pow(16, nDigits - 1); error = Application.GetLastError(); if error == 0 then sValue = String.TrimLeft(sValue, sIn); nDigits = nDigits - 1; else sTotal = ""; bFigErr = true; break; end end if not bFigErr then sTotal = nTotal..""; end return sTotal; end
to report: Language 1033 – English.Code:sOfficeLanguage = sOfficeLanguageCode.." - "..Language(sOfficeLanguageCode);
BUT, the Windows language codes are hexadecimal values (and I had built my table with decimal values only. But now:
and I get: Language: 1044 – Norwegian (from 0414h)Code:sOSLangCodeHex = Registry.GetValue(HKEY_LOCAL_MACHINE, sRegKey, "InstallLanguage", true); sOSLanguageCode = Hex2Dec(sOSLangCodeHex); sOSlanguage = sOSLanguageCode.." - "..Language(sOSLanguageCode);

