forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryEncode.lcdoc
More file actions
101 lines (76 loc) · 3.78 KB
/
Copy pathbinaryEncode.lcdoc
File metadata and controls
101 lines (76 loc) · 3.78 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Name: binaryEncode
Type: function
Syntax: binaryEncode(<formatsList>, <dataStringList>)
Summary:
<encode|Encodes> a set of <value|values> into a single <binaryvalue>.
Introduced: 1.0
OS: mac, windows, linux, ios, android
Platforms: desktop, server, mobile
Example:
binaryEncode("a","Q") -- returns "Q"
Example:
binaryEncode("A5","QED") -- returns "QED "
Example:
binaryEncode("N2a12x",firstNum,secondNum,labelString,"nothing")
Example:
charToNum(binaryEncode("B*","01111111")) -- returns 127
Parameters:
formatsList:
The formatsList consists of one or more dataTypes, each followed
optionally by an amount. A dataType is one of the following single
letters: x: output amount null characters
dataStringList (string):
A comma-separated list of dataStrings. Each dataString is a string, or
an expression that evaluates to a string.
amount (enum):
- If the dataType is a, A, b, B, h, or H, the amount specifies the
number of characters or groups of the dataString to use; extra
characters are ignored. The * character Encodes the rest of the data
in the current dataString. If no amount is specified, the dataType is
used for one character.
- If the dataType is c, C, s, S, i, I, n, N, m, M, f, or d, the amount
specifies the number of dataStrings to encode. The * character
Encodes the rest of the dataStrings. If no amount is specified, the
dataType is used for one dataString.
- If the dataType is x, the amount specifies how many nulls to place in
the returned value.
- byte integersC: encode amount numbers as unsigned 1-byte integerss:
encode amount numbers as signed 2-byte integers in host byte orderS:
encode amount numbers as unsigned 2-byte integers in host byte
orderi: encode amount numbers as signed 4-byte integers in host byte
orderI: encode amount numbers as unsigned 4-byte integers in host
byte ordern: encode amount numbers as signed 2-byte integers in
network byte orderN: encode amount numbers as signed 4-byte integers
in network byte orderm: encode amount numbers as unsigned 2-byte
integers in network byte orderM: encode amount numbers as unsigned
4-byte integers in network byte orderf: encode amount numbers as
single-precision floating-point numbersd: encode amount numbers as
double-precision floating-point numbersThe amount corresponding to
each dataType is an integer or the * character:
Returns:
The <binaryEncode> <function> <return|returns> the binary string
representation of the dataStrings.
The result:
Although the x dataType places <null|nulls> in the resulting <string>
regardless of the contents of its corresponding dataString, you still
must provide a dataString for instances of x that appear in the
<formatsList>. The <binaryEncode> <function> disregards the contents of
the dataString used for the dataType x, so you can use any value.
Description:
Use the <binaryEncode> function to <encode> one or more <value|values>
as <binary file|binary data>.
The binary data format produced by <binaryEncode> is similar to the
<format> produced by the "pack()" function of the Perl programming
language.
If you don't specify a number with the a, A, b, B, h, or H dataTypes,
one <character> is <encode|encoded>. If the dataType normally takes more
than one <character>, trailing zeroes are added to make up the required
number of <characters>. For example, H requires two characters, so
binaryEncode("H","3") <encode|Encodes> the <hexadecimal> number 30,
adding a zero to the end to make the dataString two <characters> long.
References: function (control structure), numToChar (function),
format (function), return (glossary), binary file (glossary),
value (glossary), null (glossary), encode (glossary),
binaryvalue (glossary), hexadecimal (glossary), string (keyword),
character (keyword), characters (keyword)
Tags: text processing