## UINT16 Convert to Unsigned 16-bit Integer

Section: Type Conversion Functions

### Usage

Converts the argument to an unsigned 16-bit Integer. The syntax for its use is

       y = uint16(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 an unsigned 16-bit integer of `[0,65535]`, the least significant 16 bits of `x` are used after conversion to an integer). Note that both `NaN` and `Inf` both map to 0.

### Example

The following piece of code demonstrates several uses of `uint16`.

    --> uint16(200)

    ans =

     200

    -->
    quit

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

    --> uint16(99400)

    ans =

     33864

    -->
    quit

In the next example, a negative integer is passed in. The result is the 16 least significant bits of the argument, \emph{after} taking the 2's complement.

    --> uint16(-100)

    ans =

     65436

    -->
    quit

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

    --> uint16(pi)

    ans =

     3

    -->
    quit

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

    --> uint16(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.

    --> uint16('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.

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