Navigation

Operators and Keywords

Function List:

C++ API

: y = typecast (x, "class")

Return a new array y resulting from interpreting the data of x in memory as data of the numeric class class.

Both the class of x and class must be one of the built-in numeric classes:

"logical"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
"double"
"single"
"double complex"
"single complex"

the last two are only used with class; they indicate that a complex-valued result is requested. Complex arrays are stored in memory as consecutive pairs of real numbers. The sizes of integer types are given by their bit counts. Both logical and char are typically one byte wide; however, this is not guaranteed by C++. If your system is IEEE conformant, single and double will be 4 bytes and 8 bytes wide, respectively. "logical" is not allowed for class.

If the input is a row vector, the return value is a row vector, otherwise it is a column vector.

If the bit length of x is not divisible by that of class, an error occurs.

An example of the use of typecast on a little-endian machine is

x = uint16 ([1, 65535]);
typecast (x, "uint8")
⇒ [   1,   0, 255, 255]

See also: cast, bitpack, bitunpack, swapbytes.

Package: octave