## INT8 Convert to Signed 8-bit Integer

Section: Type Conversion Functions

### Usage

Converts the argument to an signed 8-bit Integer. The syntax for its use is

       y = int8(x)

where `x` is an `n`-dimensional numerical array. Conversion follows the general C rules (e.g., if `x` is outside the normal range for a signed 8-bit integer of `[-128,127]`, the least significant 8 bits of `x` are used after conversion to a signed integer). Note that both `NaN` and `Inf` both map to 0.

### Example

The following piece of code demonstrates several uses of `int8`. First, the routine uses

    --> int8(100)

    ans =

     100

    --> int8(-100)

    ans =

     -100

    -->
    quit

In the next example, an integer outside the range of the type is passed in. The result is the 8 least significant bits of the argument.

    --> int8(400)

    ans =

     -112

    -->
    quit

In the next example, a positive double precision argument is passed in. The result is the signed integer that is closest to the argument.

    --> int8(pi)

    ans =

     3

    -->
    quit

In the next example, a complex argument is passed in. The result is the signed integer that is closest to the real part of the argument.

    --> int8(5+2*i)

    ans =

     5

    -->
    quit

In the next example, a string argument is passed in. The string argument is converted into an integer array corresponding to the ASCII values of each character.

    --> int8('helo')

    ans =

     104 101 108 111

    -->
    quit

In the last example, a cell-array is passed in. For cell-arrays and structure arrays, the result is an error.

    --> int8({4})
    Error: Cannot convert cell-arrays to any other type.
    -->
    quit