Binary Data

By now probably everyone who has ever used a computer for more than a week has heard that at their core, computers work with ’1’s and ’0’s, on and off, true and false. This is called binary data, because there are only two options. Fortunately, users don’t ever have to deal with raw binary data. The programmers take the ’1’s and ’0’s and give them structure to create text, numbers, pictures, and other complex elements. It’s not much fun, and it’s rarely necessary, but Panorama does allow a procedure programmer to work with raw unstructured, binary data ’1’s and ’0’s.
Older versions of Panorama allowed binary data to be stored in text fields or variables. Since Panorama now supports Unicode text, this is no longer possible. Instead, binary data now has its own data type. If you want to store binary data in a database field, you must specify that the field contains binary data. In a formula or procedure binary data is automatically generated by a number of functions, including:

byte(

word(

longword(

longlongword(

folder(

fileload(

rgb(

hsb(

rectangle(

rectangleadjust(

rectanglecenter(

rectanglesize(

point(

The fundamental unit of computer information is a bit. A bit contains a single 1 or 0. However, a bit is too small to be of much use by itself, so usually several bits are grouped together into a collection called a byte, word, or longword.

A byte is a collection of 8 bits. There are 256 possible combinations of 1’s and 0’s within a byte (2 multiplied by itself 8 times, i.e 2*2*2*2*2*2*2*2=256). These 256 combinations could represent characters, they could represent numbers from 0 to 256 or anything else. The byte( function takes a number from 0 to 255 and converts it into the corresponding pattern of 8 bits.

A word is a collection of 16 bits (or 2 bytes). There are 65,536 possible combinations of 1’s and 0’s within a word (2 multiplied by itself 16 times). These 65,536 possible combinations could represent numbers from 0–65,535 or they could represent 65,536 of anything else. The word( function takes a number from 0 to 65,536 and converts it into the corresponding pattern of 16 bits.

A longword is a collection of 32 bits (or 4 bytes). There are over 4 billion possible combinations of 1’s and 0’s within a longword (2 multiplied by itself 32 times). The longword( function takes a number from 0 to 4,294,967,295 and converts it into the corresponding pattern of 32 bits.

A longlongword is a collection of 64 bits (or 8 bytes). There are over 18 quintillion possible combinations of 1’s and 0’s within a longlongword (2 multiplied by itself 64 times). The longlongword( function takes a number and converts it into the corresponding pattern of 64 bits.

Binary values are created with the byte(, word( and longword( functions. The example below builds a text data value from a longword, a word, a word and a byte. The resulting text item has a length of 9 (4+2+2+1).

```
global rawData
rawData=
longword(96345)+
word(1249)+
word(9004)+
byte(80)
```

Numeric values can be recovered from a text data item with the binaryvalue( function. The text input into this function must have a length of 1, 2, or 4. You can use text funnels to control the position and length of the data being converted. The example below will extract four values from a text item that is at least 9 bytes long.

```
global rawData
local myLong,myFirstWord,mySecondWord,myByte
myLong=binaryvalue(rawData[1;4])
myFirstWord=binaryvalue(rawData[5;2])
mySecondWord=binaryvalue(rawData[7;2])
myByte=binaryvalue(rawData[9;1])
```

If rawData contains the information stored in it from the previous example, myLong will be 96345, myFirstWord will be 1249, mySecondWord will be 9004, and myByte will be 80.

**See Also**

- bigendianbinaryvalue( -- converts big endian binary data (a byte, word, or longword) into an unsigned number (see Binary Data).
- binarydatabuild( -- builds a binary value by scanning a database and assembling individual binary values for every record (including unselected records) in the database.
- binarytotext( -- converts binary data into text, optionally using a specified encoding.
- binaryvalue( -- converts binary data (a byte, word, longword, or longlongword) into a number (see Binary Data).
- byte( -- converts a number into a single byte of binary data (see Binary Data).
- bytearray( -- extracts a value from an array of bytes (see [Binary Data]).
- bytepattern( -- converts a byte count to text: 543 Bytes, 543 Kb, 123 Mb, 3.2 Gb
- chunkarray( -- extracts a binary "chunk" from binary data (see Binary Data).
- Data Arrays -- A numbered collection of data values.
- Data Dictionaries -- Overview of Panorama's key/value data dictionaries.
- hex( -- converts a text item containing a hexadecimal number into a standard number (decimal).
- hexbyte( -- converts a limited range of decimal numbers to a two-digit hexadecimal number expressed as a text string.
- hexlong( -- converts a decimal number to an eight-digit hexadecimal number expressed as a text string
- hexstr( -- converts a number to text formatted as a hexadecimal number.
- hextobinary( -- converts a sequence of hexadecimal digits into a raw binary data value.
- hexword( -- converts a decimal number to a four-digit hexadecimal number expressed as a text string.
- littleendianbinaryvalue( -- converts little endian binary data (a byte, word, longword, or longlongword) into an unsigned number (see Binary Data).
- longlongword( -- converts a number into a 64 bit longword (8 bytes) of binary data (see Binary Data).
- longlongwordarray( -- extracts a value from an array of 64 bit longlongwords (see [Binary Data]).
- longword( -- converts a number into a 32 bit longword (4 bytes) of binary data (see Binary Data).
- longwordarray( -- extracts a value from an array of 32 bit longwords (see [Binary Data]).
- radix( -- converts a text item containing a number in a radix between 2 and 36 into a decimal number.
- radixstr( -- converts a number into a text item containing the equivalent number in a radix between 2 and 36.
- signedbinaryvalue( -- converts binary data (a byte, word, longword, or longlongword) into a signed number (see Binary Data).
- texttobinary( -- converts text into binary data, optionally using a specified encoding.
- word( -- converts a number into a single word (2 bytes) of binary data (see Binary Data).
- wordarray( -- extracts a value from an array of 16 bit words (see Binary Data).

**History**

Version | Status | Notes |

10.0 | Updated | Binary data now has its own separate data type. You can no longer store binary data in text fields and variables. |