ConvertFromBase ( )

Function stats

Average user rating
148
365
9999
Support
FileMaker 7.0 +
Date posted
18 January 2014
Version
1
Recursive function
Yes

Author Info
 Steve Allen

15 functions

Average Rating 5.0

author_avatar



 

Function overview

Prototype

ConvertFromBase  ( str;   base;   charSet )


Parameters

str  The representation in the specified base of the number to be converted to decimal.


base  The base to be converted from.


charSet  The character set describing the representation of the values for the starting base, as used in the supplied string.


Description

Tags:  Number Representation   conversion   base  

Converts any number to decimal, so long as the base of the supplied number is specified, and the character set used to represent the number is described.

Examples

Sample input

Ex. 1: ConvertFromBase ( "1G" ; 19 ; "0123456789ABCDEFGHI" )
Ex. 2: ConvertFromBase ( "@$1*" ; 7 ; "1!@#$%^" )
Ex. 3: ConvertFromBase ( 100100010 ; 2 ; "01" )


Sample output

Ex. 1: 35
Ex. 2: 881
Ex. 3: 290

 

Function code

/*
* Created: 2014-01-16
* By: Steven R. Allen, Richard Carlton Consulting, Inc.
* Version: 1.0
*
* Purpose: Conversion of representation of a number any base and any character set to decimal with Arabic numeral representation.
*
* Notes:
* - There is one restriction that I can think of: each value that could go in any particular place has to be represented by a single character; what character is used for what value is completely arbitrary, however.
*
* - Also, there is an assumption that the character set is coded to values starting at zero on the left, and rising by +1 as it proceeds to the right, like we are used to reading the arabic numeral sequence 0123456789, etc.
*/

Case ( not IsEmpty ( number ) ;

Let ([
    power = Length ( number ) - 1
;    place = base ^ power
;    character = Left ( number ; 1 )
;    value = Position ( charSet ; character ; 1 ; 1 ) - 1
];    

( value * place ) + Case ( power ; ConvertFromBase ( Right ( number ; Length ( number ) - 1 ) ; base ; charSet ) )

) ; 0 )

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/365

    Prototype: ConvertFromBase( str; base; charSet )
    Function Author: Steve Allen (http://www.fmfunctions.com/mid/148)
    Last updated: 18 January 2014
    Version: 1

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (12)
Filter  (11)
Layout Objects  (11)
Design  (10)
Array  (8)