View Full Version : Help Please - How to convert Decimal Numbers to Hex ?
steven
08-03-2006, 10:55 AM
Hello :)
I am having some problem to convert Decimal to Hex whit two imput Box, can somebody help me whit this, please? :huh
http://img332.imageshack.us/img332/293/qwqwqwqwqwwtv3.jpg
Best Regards, steven :yes
yosik
08-03-2006, 11:58 AM
Check this thread
http://www.indigorose.com/forums/showthread.php?t=10192&highlight=hex
steven
08-03-2006, 12:12 PM
Tks yosik
Where can i place this code for this to work :o
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
:huh
i have a Imput1 and a input2 and no button?
Sorry about the english ;)
yosik
08-03-2006, 12:25 PM
function can be in the global function panel. But you have to call it when you want it.
Make a button which will call upon the function and send the result to the second input object.
Yossi
steven
08-03-2006, 05:23 PM
hello again and tanks for your help and your time :yes
i dont understand very well all words from those examples that i tried to read here and it very dificult to me to make those code to work. Can you make a example of this code in a *.apz file for me?
I know that is not the right way, but for me thats more easy to understand how that realy works.
Tanks again for your help :D
steven
08-04-2006, 04:23 AM
function can be in the global function panel....
:yes
... But you have to call it when you want it...
How can i do that? :rolleyes
yosik
08-04-2006, 05:05 AM
You have 3 objects on your page:
Input1 (this is where you input your decimal number)
Input2 (this is where you will see the converted number to hex)
Button1 (to launch your conversion)
In your Global functions, put the following:
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
In your onClick event of your button object, put the following:
decNmbr = String.ToNumber(Input.GetText("Input1"));
Dec2Hex(decNmbr);
Input.SetText("Input2",sHexVal);
That's it
Yossi
steven
08-04-2006, 05:30 AM
Tanks for your time and help yosik's :yes
:yes :yes :yes :yes
;)
steven
08-04-2006, 07:04 AM
hello again :)
Just a little explanation more please..
Whem a place a value for example 4 the result in Hex is 4, but i want that the display result wase 0004, how can we do that?
Examples:
DEC ------ HEX ------------- RESULT that i want to look like
1 --------> 1 ---------------- 0001
10 -------> A ---------------- 000A
20 -------> 14 --------------- 0014
5000 ----> 1388 ------------- 1388
when the result dosent have 4 numbers it should place zeros just like in the examples.
Tks again for your tine whith me :yes
TJ_Tigger
08-04-2006, 07:31 AM
LUA has a built in function called string.format. You can use this to force a string to four characters with leading zeros.
Input.SetText("Input2", string.format("%04s", sHexVal));
Tigg
steven
08-04-2006, 08:40 AM
Ok y understand now :yes
Tanks TJ_Tigger and yosik :yes :yes :yes
Intrigued
08-04-2006, 06:30 PM
When it comes to AMS, those two guys are a "One Two Knockout". I just have not figured out who is "one" and who is "two."
;) @ 'Tig and Yosik
yosik
08-05-2006, 04:04 PM
Right backatcha, Intrigued... ;)
Yossi
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.