Convert Hex String to Number

Version 3

    Description:

    Tableau's built in functions do not include support for hex representations of numbers.

    This calculation converts a hex string to an integer.

    Example Calculation:

    Given a string of hex digits, first define a calculated field [Pad Hex], as follows:


    RIGHT("00000000" + UPPER([Hex]), 8)


    Then define this calculation in terms on the resulting zero padded and upper case string.

     

    (ASCII(RIGHT([Pad Hex],1))-IIF(ASCII(RIGHT([Pad Hex],1))<58,48,55))*(16^0)+
    (ASCII(RIGHT([Pad Hex],2))-IIF(ASCII(RIGHT([Pad Hex],2))<58,48,55))*(16^1)+
    (ASCII(RIGHT([Pad Hex],3))-IIF(ASCII(RIGHT([Pad Hex],3))<58,48,55))*(16^2)+
    (ASCII(RIGHT([Pad Hex],4))-IIF(ASCII(RIGHT([Pad Hex],4))<58,48,55))*(16^3)+
    (ASCII(RIGHT([Pad Hex],5))-IIF(ASCII(RIGHT([Pad Hex],5))<58,48,55))*(16^4)+
    (ASCII(RIGHT([Pad Hex],6))-IIF(ASCII(RIGHT([Pad Hex],6))<58,48,55))*(16^5)+
    (ASCII(RIGHT([Pad Hex],7))-IIF(ASCII(RIGHT([Pad Hex],7))<58,48,55))*(16^6)+
    (ASCII(RIGHT([Pad Hex],8))-IIF(ASCII(RIGHT([Pad Hex],8))<58,48,55))*(16^7)
    


    [Hex] - a string field or parameter, from 1 to 8 characters long, containing only valid hex digits (0-9, A-F, a-f).

     

    Comments:

    Note that the calculation does not attempt to validate that the input string is not greater than 8 characters long and that it only contains valid hex characters. If either of those conditions is not met the result will be incorrect.

     

    Related Functions:

    Convert Number to Hex String.

     

    Further Reading/Examples:

    This calculation is based on one developed in this forum thread.