forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryEncode.xml
More file actions
49 lines (49 loc) · 6.85 KB
/
Copy pathbinaryEncode.xml
File metadata and controls
49 lines (49 loc) · 6.85 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
<doc>
<legacy_id>2232</legacy_id>
<name>binaryEncode</name>
<type>function</type>
<syntax>
<example>binaryEncode(<i>formatsList</i>,<i>dataStringList</i>)</example>
</syntax>
<library></library>
<objects>
</objects>
<synonyms>
</synonyms>
<classification>
<category>Text and Data Processing</category>
</classification>
<references>
<function tag="numToChar">numToChar Function</function>
<function tag="format">format Function</function>
</references>
<history>
<introduced version="1.0">Added.</introduced>
<changed version="2.9"></changed>
</history>
<platforms>
<mac/>
<windows/>
<linux/>
<ios/>
<android/>
</platforms>
<classes>
<desktop/>
<server/>
<web/>
<mobile/>
</classes>
<security>
</security>
<summary><glossary tag="encode">Encodes</glossary> a set of <glossary tag="value">values</glossary> into a single <glossary tag="binary">binaryvalue</glossary>.</summary>
<examples>
<example>binaryEncode("a","Q") <i>-- returns "Q"</i></example>
<example>binaryEncode("A5","QED") <i>-- returns "QED "</i></example>
<example>binaryEncode("N2a12x",firstNum,secondNum,labelString,"nothing")</example>
<example>charToNum(binaryEncode("B*","01111111")) <i>-- returns 127</i></example>
</examples>
<description>
<p>Use the <b>binaryEncode</b> function to <glossary tag="encode">encode</glossary> one or more <glossary tag="value">values</glossary> as <glossary tag="binary data">binary data</glossary>.</p><p/><p><b>Parameters:</b></p><p>The <i>formatsList</i> consists of one or more <i>dataTypes</i>, each followed optionally by an <i>amount</i>. A <i>dataType</i> is one of the following single letters:</p><p/><p>x: output <i>amount</i> <constant tag="null">null</constant> characters</p><p>a: encode <i>amount</i> <keyword tag="characters">characters</keyword> as <keyword tag="characters">characters</keyword>, <glossary tag="pad">padding</glossary> with nulls</p><p>A: encode <i>amount</i> <keyword tag="characters">characters</keyword> as <keyword tag="characters">characters</keyword>, <glossary tag="pad">padding</glossary> with spaces</p><p>b: encode <i>amount</i> groups of 4 1s and 0s as bits</p><p>B: encode <i>amount</i> groups of 4 1s and 0s as <glossary tag="bit">bits</glossary>, starting at the high end of each byte</p><p>h: encode <i>amount</i> groups of 2 characters as <glossary tag="hexadecimal">hexadecimal</glossary> numbers</p><p>H: encode <i>amount</i> groups of 2 characters as <glossary tag="hexadecimal">hexadecimal</glossary>, starting at the high end of each byte</p><p>c: encode <i>amount</i> numbers as signed 1-byte integers</p><p>C: encode <i>amount</i> numbers as unsigned 1-byte integers</p><p>s: encode <i>amount</i> numbers as signed 2-byte <glossary tag="integer">integers</glossary> in host byte order</p><p>S: encode <i>amount</i> numbers as unsigned 2-byte <glossary tag="integer">integers</glossary> in host byte order</p><p>i: encode <i>amount</i> numbers as signed 4-byte <glossary tag="integer">integers</glossary> in host byte order</p><p>I: encode <i>amount</i> numbers as unsigned 4-byte <glossary tag="integer">integers</glossary> in host byte order</p><p>n: encode <i>amount</i> numbers as signed 2-byte <glossary tag="integer">integers</glossary> in network byte order</p><p>N: encode <i>amount</i> numbers as signed 4-byte <glossary tag="integer">integers</glossary> in network byte order</p><p>m: encode <i>amount</i> numbers as unsigned 2-byte integers in network byte order</p><p>M: encode <i>amount</i> numbers as unsigned 4-byte integers in network byte order</p><p>f: encode <i>amount</i> numbers as single-precision floating-point numbers</p><p>d: encode <i>amount</i> numbers as double-precision floating-point numbers</p><p/><p>The <i>amount</i> corresponding to each <i>dataType</i> is an <keyword tag="integer">integer</keyword> or the * <keyword tag="character">character</keyword>:</p><p/><p>* If the <i>dataType</i> is a, A, b, B, h, or H, the <i>amount</i> specifies the number of <keyword tag="characters">characters</keyword> or groups of the <i>dataString</i> to use; extra <keyword tag="characters">characters</keyword> are ignored. The * <keyword tag="character">character</keyword> <glossary tag="encode">Encodes</glossary> the rest of the data in the current <i>dataString</i>. If no <i>amount</i> is specified, the <i>dataType</i> is used for one <keyword tag="character">character</keyword>.</p><p/><p>* If the <i>dataType</i> is c, C, s, S, i, I, n, N, m, M, f, or d, the <i>amount</i> specifies the number of <i>dataStrings</i> to <glossary tag="encode">encode</glossary>. The * <keyword tag="character">character</keyword> <glossary tag="encode">Encodes</glossary> the rest of the <i>dataStrings</i>. If no <i>amount</i> is specified, the <i>dataType</i> is used for one <i>dataString</i>.</p><p/><p>* If the <i>dataType</i> is x, the <i>amount</i> specifies how many <glossary tag="null">nulls</glossary> to place in the <glossary tag="return value">returned value</glossary>.</p><p/><p>The <i>dataStringList</i> is a comma-separated list of <i>dataStrings</i>. Each <i>dataString</i> is a <keyword tag="string">string</keyword>, or an <glossary tag="expression">expression</glossary> that <glossary tag="evaluate">evaluates</glossary> to a <keyword tag="string">string</keyword>.</p><p/><p><b>Value:</b></p><p>The <b>binaryEncode</b> <control_st tag="function">function</control_st> <glossary tag="return">returns</glossary> the binary string representation of the <i>dataStrings</i>.</p><p/><p><b>Comments:</b></p><p>The binary data format produced by <b>binaryEncode</b> is similar to the <function tag="format">format</function> produced by the "pack()" function of the Perl programming language.</p><p/><p>Although the x <i>dataType</i> places <glossary tag="null">nulls</glossary> in the resulting <keyword tag="string">string</keyword> regardless of the contents of its corresponding <i>dataString</i>, you still must provide a <i>dataString</i> for instances of x that appear in the <i>formatsList</i>. The <b>binaryEncode</b> <control_st tag="function">function</control_st> disregards the contents of the <i>dataString</i> used for the <i>dataType</i> x, so you can use any value.</p><p/><p>If you don't specify a <i>number</i> with the a, A, b, B, h, or H <i>dataTypes</i>, one <keyword tag="character">character</keyword> is <glossary tag="encode">encoded</glossary>. If the <i>dataType</i> normally takes more than one <keyword tag="character">character</keyword>, trailing zeroes are added to make up the required number of <keyword tag="characters">characters</keyword>. For example, H requires two characters, so binaryEncode("H","3") <glossary tag="encode">Encodes</glossary> the <glossary tag="hexadecimal">hexadecimal</glossary> number 30, adding a zero to the end to make the <i>dataString</i> two <keyword tag="characters">characters</keyword> long.</p>
</description>
</doc>