Error getting tags :
error 404Error getting tags :
error 404 binaryEncode | revDocs | RunRev
Welcome Guest (Log in)
Product Edition
Version
binaryEncode
Basics
Expander triangle
Type
Function
Syntax

binaryEncode(formatsList,dataStringList)

Introduced
1.0
Changed
2.9
Environment
Desktop, Web and Server
Platform Support
MacOS,Mac OS X,Windows,Linux
Security
None required
Summary
Encodes a set of values into a single binaryvalue.
Examples

binaryEncode("a","Q") -- returns "Q"
binaryEncode("A5","QED") -- returns "QED "
binaryEncode("N2a12x",firstNum,secondNum,labelString,"nothing")
charToNum(binaryEncode("B*","01111111")) -- returns 127

Additional Comments
Expander triangle

Use the binaryEncode function to encode one or more values as binary data.

Parameters:

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

a: encode amount characters as characters, padding with nulls

A: encode amount characters as characters, padding with spaces

b: encode amount groups of 4 1s and 0s as bits

B: encode amount groups of 4 1s and 0s as bits, starting at the high end of each byte

h: encode amount groups of 2 characters as hexadecimal numbers

H: encode amount groups of 2 characters as hexadecimal, starting at the high end of each byte

c: encode amount numbers as signed 1-byte integers

C: encode amount numbers as unsigned 1-byte integers

s: encode amount numbers as signed 2-byte integers in host byte order

S: encode amount numbers as unsigned 2-byte integers in host byte order

i: encode amount numbers as signed 4-byte integers in host byte order

I: encode amount numbers as unsigned 4-byte integers in host byte order

n: encode amount numbers as signed 2-byte integers in network byte order

N: encode amount numbers as signed 4-byte integers in network byte order

m: encode amount numbers as unsigned 2-byte integers in network byte order

M: encode amount numbers as unsigned 4-byte integers in network byte order

f: encode amount numbers as single-precision floating-point numbers

d: encode amount numbers as double-precision floating-point numbers

The amount corresponding to each dataType is an integer or the * character:

* 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.

The dataStringList is a comma-separated list of dataStrings. Each dataString is a string, or an expression that evaluates to a string.

Value:

The binaryEncode function returns the binary string representation of the dataStrings.

Comments:

The binary data format produced by binaryEncode is similar to the format produced by the "pack()" function of the Perl programming language.

Although the x dataType places 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.

If you don't specify a number with the a, A, b, B, h, or H dataTypes, one character is 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") encodes the hexadecimal number 30, adding a zero to the end to make the dataString two characters long.

User Comments
Expander triangle