Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2006
    Posts
    38

    Help Please - How to convert Decimal Numbers to Hex ?

    Hello

    I am having some problem to convert Decimal to Hex whit two imput Box, can somebody help me whit this, please?



    Best Regards, steven

  2. #2
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843

  3. #3
    Join Date
    Jul 2006
    Posts
    38
    Tks yosik

    Where can i place this code for this to work

    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 have a Imput1 and a input2 and no button?

    Sorry about the english

  4. #4
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843
    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

  5. #5
    Join Date
    Jul 2006
    Posts
    38
    hello again and tanks for your help and your time
    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

  6. #6
    Join Date
    Jul 2006
    Posts
    38
    Quote Originally Posted by yosik
    function can be in the global function panel....


    Quote Originally Posted by yosik
    ... But you have to call it when you want it...
    How can i do that?

  7. #7
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843
    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

  8. #8
    Join Date
    Jul 2006
    Posts
    38
    Tanks for your time and help yosik's




  9. #9
    Join Date
    Jul 2006
    Posts
    38
    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

  10. #10
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  11. #11
    Join Date
    Jul 2006
    Posts
    38
    Ok y understand now

    Tanks TJ_Tigger and yosik

  12. #12
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    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
    Intrigued

  13. #13
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843
    Right backatcha, Intrigued...

    Yossi

Similar Threads

  1. Convert Hexadecimal to Decimal
    By csd214 in forum AutoPlay Media Studio 5.0
    Replies: 12
    Last Post: 04-05-2010, 02:26 AM
  2. Decimal to Hex
    By nrgyzer in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 02-25-2006, 07:34 AM
  3. Color Picker - Hex to Decimal - Convert
    By Intrigued in forum AutoPlay Media Studio 6.0
    Replies: 0
    Last Post: 11-20-2005, 12:26 AM
  4. Adding Hex numbers
    By mrdude in forum AutoPlay Media Studio 6.0
    Replies: 1
    Last Post: 09-23-2005, 03:22 PM
  5. Program: Binary Hex and Decimal Converter
    By Protocol in forum AutoPlay Media Studio 5.0 Examples
    Replies: 3
    Last Post: 07-15-2004, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts