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(

Bits

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.

Bytes

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 255 or anything else. The byte( function takes a number from 0 to 255 and converts it into the corresponding pattern of 8 bits.

Words

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.

Longwords

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.

Longlongwords

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.

Creating Binary Values

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)

Accessing Binary Information

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


History

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