-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAsciiToBin.fmfn
58 lines (51 loc) · 1.95 KB
/
AsciiToBin.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
58
/*
------------------------------------------------------------------------------
Purpose: Converts ASCII text to binary text representation of
0's and 1's
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 - ASCII text to be converted to binary text
Data Type Returned:
text
Variables:
$$intCode - Integer representation of the ASCII character
$$binary - Binary text representation of the ASCII text
~return - Returns the binary text representation of ASCII text
Depends On:
IntToByte( number )
Revision:
Last change: 27/09/2015 by JMT
::
27/09/2015 - JMT - Wrote original script
------------------------------------------------------------------------------
*/
Let (
[
// Get the ASCII code for the first character in the text
intCode = Code ( Left ( text; 1 ) );
// Add the current ASCII character's binary representation to the existing binary text
// Windows encodes a new line character as both /r/n, and so its Code() conversion needs
// to be handled specially as IntToBin( number ) does not convert properly
$$binary = $$binary & If( intCode = 1000013 ; "00001010" ; IntToByte ( GetAsNumber ( intCode ) ) );
// Save the ASCII text as a local variable so that the global
// variable can be cleared before exiting the function
~return = $$binary
];
If ( Length ( text ) > 1;
// Convert the next ASCII character to binary if not at the
// end of hte ASCII text
AsciiToBin ( Right ( text ; Length( text ) - 1 ) );
// Clear the global variables and return the binary text if
// there are no more characters to convert
Let(
[
$$binary = "";
$$carriage = ""
];
~return
)
)
)