Casts the values of a series to a new data type.
CASTBYTE(series, datatype, swapflag, byteflag)
series |
- |
A series, the input values to convert. |
datatype |
- |
Optional. An integer, the binary data type for the output values described by either its macro name or integer code. Defaults to DOUBLE. Valid arguments are: |
Name |
Code |
Data Type |
Range |
INT8 SBYTE |
1 |
8-bit Signed Byte |
-128 to +127 |
UINT8 UBYTE BYTE |
2 |
8-bit Unsigned Byte |
0 to 255 |
INT16 SINT |
3 |
16-bit (2-byte) Signed Integer |
-32768 to +32767 |
UINT16 UINT |
4 |
16-bit (2-byte) Unsigned Integer |
0 to 65535 |
INT32 LONG |
5 |
32-bit (4-byte) Signed Integer |
-2,147,483,648 to +2,147,483,647 |
FLOAT |
6 |
32-bit (4-byte) Floating Point |
-1037 to +1038 |
DOUBLE |
7 |
64-bit (8-byte) Floating Point |
-10-307 to +10308 |
UINT32 ULONG |
8 |
32-bit (4-byte) Unsigned Integer |
0 to 4,294,967,295 |
INT64 |
9 |
64-bit (8-byte) Signed Integer |
-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 |
UINT64 |
10 |
64-bit (8-byte) Unsigned Integer |
0 to 18,446,744,073,709,551,615 |
|
1000 + N |
N-byte Signed Integer |
-28N-1 to 28N-1-1 |
|
2000 + N |
N-byte Unsigned Integer |
0 to 28N-1 |
swapflag |
- |
Optional. An integer, the swap bytes flag:
|
|||||||||
byteflag |
- |
Optional. An integer, the input series treatment:
|
A series or table.
castbyte(W1, UINT8)
converts the values in W1 into unsigned bytes ranging from 0 to 255.
castbyte(W1, UBYTE)
converts the values in W1 into unsigned bytes ranging from 0 to 255.
writeb("bytedata", FLOAT, -5..5);
bdata = readb("bytedata", BYTE);
fdata = castbyte(bdata, FLOAT, 0, 1);
The original 11 point series is written to the file bytedata as 4 byte floating point values The file is 44 bytes long. Series bdata reads the file as raw bytes and is also 44 points long. Series fdata converts every 4 values of bdata into a floating point value thus recovering the original 11 point series.
a = 1..4;
b = castbyte(a, FLOAT, 0, 2);
c = castbyte(b, FLOAT, 0, 1);
Variable a contains the series {1, 2, 3, 4}. Variable b contains 16 values where every 4 values are the byte representation of the original data as 4 byte FLOAT values. Variable c converts every 4 bytes of FLOAT data of variable b back to the original values of variable a.
sine3 = int(100 * gsin(100, 1/100, 2));
writeb("sine3.dat", 1003, sine3);
bdata = readb("sine3.dat", ubyte);
idata = castbyte(bdata, 1003, 0, 1)
A sinewave of 3 byte signed integers is written to the file sine3.dat. The data is read as a stream of unsigned bytes and CASTBYTE converts the data to the original 3 byte signed integer format. The special datatype value of 1000 + N specifies an N byte signed integer value.
If byteflag is 0, each value of the input series is converted from the original double precision value to the specified type.
If byteflag is 1, the input series is treated a raw byte values. Each value of the input series is first converted to a single byte value. Then every N byte values are combined and converted to the specified type where N is the size of the type.
If byteflag is 2, the input series is treated as double precision values that are converted to a raw byte stream. Every N values of the result represent the original data converted to the specified type where N is the size of the type.
CASTBYTE also supports N byte integer format to read signed or unsigned multiple bytes as integer values. A datatype value of 1000 + N specifies N byte signed integer values and 2000 + N specifies N byte unsigned integer values. For example:
1003
implies a 3 byte signed integer values.
2005
implies a 5 byte unsigned integer values.
See BYTE2TYPE and TYPE2BYTE to convert from a byte stream to a series and from a series to a byte stream.