2 Replies Latest reply on Oct 1, 2012 2:58 PM by SandyHaaf

# Hex to Decimal

### Title

Hex to Decimal

### Post

I'm trying to figure out a way to convert hex numbers to decimal.  Does filemaker pro not have built in functions for this???

Any help to point me in the right direction would be great.

Thanks,

Sandy

• ###### 1. Re: Hex to Decimal

You would have to create your own, or if you have FileMaker Advanced, you might search one of the custom function sites for such a function.

Would the number of digits in your hex number always be the same or might the number of digits vary?

Here's a simple calculation that works up to 4 digits: (A cusutom function can use recursion to compute a value for a varying number of digits)

Let ( [ hexString = Right ( Upper ( "000" & YourHexNumberHere ) ; 4 );
d1 = Left (hexString ; 1 ) ;
v1 = IF ( d1 < "9" ; GetasNumber ( d1 ) ; Code ( d1 ) - Code ("A" ) + 10 );
d2 = Middle ( hexstring ; 2 ; 1 ) ;
v2 = IF ( d2 < "9" ; GetasNumber ( d2 ) ; Code ( d2 ) - Code ("A" ) + 10 );
d3 = Middle ( hexstring ; 3 ; 1 ) ;
v3 = IF ( d3 < "9" ; GetasNumber ( d3 ) ; Code ( d3 ) - Code ("A" ) + 10 );
d4 = Middle ( hexstring ; 4 ; 1 ) ;
v4 = IF ( d4 < "9" ; GetasNumber ( d4 ) ; Code ( d4 ) - Code ("A" ) + 10 )
];
v1 * 16^3+ v2 * 16^2 + v3*16 + v4
)

• ###### 2. Re: Hex to Decimal

Thank you!  This worked with a minor tweak.  Just needed to change the < "9" to <= "9" in the if statements. See below.

Let ( [ hexString = Right ( Upper ( "000" & YourHexnumberHere ) ; 4 );
d1 = Left (hexStringIAC ; 1 ) ;
v1 = If ( d1  ≤  "9" ; GetAsNumber ( d1 ) ; Code ( d1 ) - Code ("A" ) + 10 );
d2 = Middle ( hexstring ; 2 ; 1 ) ;
v2 = If ( d2  ≤  "9" ; GetAsNumber ( d2 ) ; Code ( d2 ) - Code ("A" ) + 10 );
d3 = Middle ( hexstring ; 3 ; 1 ) ;
v3 = If ( d3  ≤  "9" ; GetAsNumber ( d3 ) ; Code ( d3 ) - Code ("A" ) + 10 );
d4 = Middle ( hexstring ; 4 ; 1 ) ;
v4 = If ( d4  ≤  "9" ; GetAsNumber ( d4 ) ; Code ( d4 ) - Code ("A" ) + 10 )
];
v1 * 16^3+ v2 * 16^2 + v3*16 + v4
)