forked from jmtritch/FileMaker_Edit_Text_Files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteToInt.fmfn
57 lines (51 loc) · 1.89 KB
/
ByteToInt.fmfn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
------------------------------------------------------------------------------
Purpose: Converts a text of eight 0's and 1's to an integer using
big endian notation
Example: "00001010" --> 10
Author: J. Michael Tritchler
Notes: This function was developed as part of importing and
exporting the contents of an ASCII text file stored
in a container field
Parameters:
text - The base64 encoded text to convert to binary
Data Type Returned:
number
Variables:
$$power - Stores the current power of 2 for converting a
single "bit", i.e. a single 0 or 1 ASCII character
$$num - Running total of the integer representation of the
binary text
~return - Returns the integer value of the binary text
Revision:
Last change: 27/09/2015 by JMT
::
27/09/2015 - JMT - Wrote original script
------------------------------------------------------------------------------
*/
Let (
[
// Get the binary multiple for the current bit in the binary number
$$power = If ( IsEmpty ( $$power ) ; 1 ; $$power * 2 );
// Calculate the integer value of the current bit and add it to the
// running total of the number
$$num = $$num + ( GetAsNumber ( Right ( text ; 1 ) ) * $$power );
// Save the integer value as a local variable so that the global
// variable can be cleared before exiting the function
~return = $$num
];
If ( Length( text ) > 1;
// Add the integer value of next bit to the total if not at the
// the end of the byte text
ByteToInt( Left ( text ; Length( text ) - 1 ) );
// Clear the global variables and return the integer value if
// there are no more bits to calculate
Let(
[
$$power = "";
$$num = ""
];
~return
)
)
)