Brian Dunning's FileMaker Custom Functions

Dec2Bin ( decimalNumber ; binaryNumber )

Converts decimal number (positive integer) to binary number

  Average rating: 4.3 (35 votes) Log in to vote

Ronald W. Satz   Ronald W. Satz
Transpower Corporation
http://www.transpowercorp.com

Share on Facebook Share on Twitter

  Sample input:
Dec2Bin ( 10000000 , "" )
  Sample output:
100110001001011010000000

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This custom function converts a base 10 number (a positive integer) to its equivalent base 2 value.

 

Comments

Vaughan Bromfield   Vaughan Bromfield
Mar 13, 2010
The function as posted does not compute: "theResult" is not defined before it is used in the Case statement. Also the function returns null if the decimal number is zero. The following changes seems to resolve both issues, but significant; testing has not been performed:

--

// Dec2Bin ( decimalNumber ; binaryNumber ) (binaryNumber is initially "")
// Converts decimal number to binary number
// By Ronald W. Satz
// 11-20-2004

Case (

decimalNumber = 0 and IsEmpty( binaryNumber ) ; 0 ; // Exit case for zero

decimalNumber = 0 ; binaryNumber ; // Exit

Let (
[
theResult = Mod ( decimalNumber ; 2 ) & binaryNumber ;
decimalNumber = Int ( decimalNumber / 2 )
] ;
Dec2Bin (decimalNumber; theResult) )

) // Case
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: