LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  hexadecimal to decimal conversion

    Employee
    Posted 06-29-2011 19:40

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: alyon

    Hi,

    Is there a brainscript function for converting hexadecimal value to a decimal value?

    I have an Inputstring which is a hexadecimal value. I want to convert it into decimal string.

    e.g.
    inputstring = A
    outputstring = 10

    inputstring = 2E
    outputstring = 46

    inputstring = 12
    outputstring = 18


    Regards
    Anshul


  • 2.  RE: hexadecimal to decimal conversion

    Employee
    Posted 06-30-2011 16:33

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jiken

    Hi alyon,

    I have built this node that takes hex data as csv input and converts to decimal. You may need to change name of input field.

    Ignore CSIAudit.brg request by clicking on Ok if prompts.

    Regards,

    Jiken
    Attachments:
    Hex2Dec.brg


  • 3.  RE: hexadecimal to decimal conversion

    Employee
    Posted 06-30-2011 23:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: alyon

    Hi Jiken,

    Thanks for your response and solution.

    I have also developed a function to do the task,


    length = hexString.strlen()
    n = 0
    decimalnumber = 0

    while(n < length)
    {
    i = hexString.substr(length-1-n, 1).switch(
    "0",0,
    "1",1,
    "2",2,
    "3",3,
    "4",4,
    "5",5,
    "6",6,
    "7",7,
    "8",8,
    "9",9,
    "A",10,
    "a",10,
    "B",11,
    "b",11,
    "C",12,
    "c",12,
    "D",13,
    "d",13,
    "E",14,
    "e",14,
    "F",15,
    "f",15,
    -1
    )

    if i == -1 then
    {
    decimalnumber = null
    break
    }

    decimalnumber = decimalnumber + (i * pow(16,n))
    n = n + 1
    }

    emit decimalnumber.str() as decimalString


    I guess both functions will do the job, but having an inbuilt function would have been easy to use

    Regards
    Anshul