KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Converting Hexadecimal values to Integer values using 4D Code
PRODUCT: 4D | VERSION: 11.6 | PLATFORM: Mac & Win
Published On: May 20, 2011

Here is a quick method that can be used for converting Hexadecimal values to Integer values using 4D code:

If (Count parameters=1)
C_TEXT($1;$thisPosition)
C_LONGINT($0;$temp)
$temp:=0
$length:=Length($1)
For ($a;1;$length)
  $thisPosition:=Substring($1;$a;1)
  Case of
    :($thisPosition="A")
     $thisPosition:="10"
    :($thisPosition="B")
     $thisPosition:="11"
    :($thisPosition="C")
     $thisPosition:="12"
    :($thisPosition="D")
     $thisPosition:="13"
    :($thisPosition="E")
     $thisPosition:="14"
    :($thisPosition="F")
     $thisPosition:="15"
  End case
  $thisMultiplier:=16^($length-$a)
  $temp:=$temp+(Num($thisPosition)*($thisMultiplier))
End for
$0:=$temp
End if


If the above code is saved as a project method named UTIL_HexToInt it could be used to convert a Hexadecimal value to an Integer value like so:

C_LONGINT($int)
$int:=UTIL_HexToInt("4D")


In the above example $int would be equal to "77".