uint16

Converts values to unsigned 16-bit integers (0 to 65535).

Category: Language Fundamentals > Data Types

Syntax

Y = uint16(X)

Converts X to class uint16.

Description

Values are rounded to the nearest integer (halves away from zero) and then saturate: anything above 65535 becomes 65535, and negative numbers and NaN become 0. No error or warning is raised. For example, uint16(70000) gives 65535.

Arithmetic between uint16 and a double gives a uint16 result, rounded and saturated again, so uint16(7)/uint16(2) is 4. Mixing two different integer classes in one operation is an error. intmax('uint16') gives the largest value.

Input arguments

X
Numeric, logical or char array.

Output arguments

Y
Array of class uint16 with the same size as X.

Example

Rounding and saturation

uint16(70000)
uint16(-5)
uint16(3.5)
class(uint16(1) + 2)
Output
ans = uint16
   65535
ans = uint16
   0
ans = uint16
   4
ans = 'uint16'

See also

int8 double intmax cast class