| MATLAB Function Reference | ![]() |
| I = uint8(X) |
| I = uint16(X) |
| I = uint32(X) |
| I = uint64(X) |
I = uint*(X) converts the elements of array X into unsigned integers. X can be any numeric object (such as a double). The results of a uint* operation are shown in the next table.
Operation | Output Range | Output Type | Bytes per Element | Output Class |
|---|---|---|---|---|
| uint8 | 0 to 255 | Unsigned 8-bit integer | 1 | uint8 |
| uint16 | 0 to 65,535 | Unsigned 16-bit integer | 2 | uint16 |
| uint32 | 0 to 4,294,967,295 | Unsigned 32-bit integer | 4 | uint32 |
| uint64 | 0 to 18,446,744,073,709,551,615 | Unsigned 64-bit integer | 8 | uint64 |
double and single values are rounded to the nearest uint* value on conversion. A value of X that is above or below the range for an integer class is mapped to one of the endpoints of the range. For example,
uint16(70000) ans = 65535
If X is already an unsigned integer of the same class, then uint* has no effect.
You can define or overload your own methods for uint* (as you can for any object) by placing the appropriately named method in an @uint* directory within a directory on your path. Type help datatypes for the names of the methods you can overload.
Most operations that manipulate arrays without changing their elements are defined for integer values. Examples are reshape, size, the logical and relational operators, subscripted assignment, and subscripted reference.
Some arithmetic operations are defined for integer arrays on interaction with other integer arrays of the same class (e.g., where both operands are uint16). Examples of these operations are +, -, .*, ./, .\ and .^. If at least one operand is scalar, then *, /, \, and ^ are also defined. Integer arrays may also interact with scalar double variables, including constants, and the result of the operation is an integer array of the same class. Integer arrays saturate on overflow in arithmetic.
Note Only the lower order integer data types support math operations. Math operations are not supported for int64 and uint64. |
A particularly efficient way to initialize a large array is by specifying the data type (i.e., class name) for the array in the zeros, ones, or eye function. For example, to create a 100-by-100 uint64 array initialized to zero, type
I = zeros(100, 100, 'uint64');
An easy way to find the range for any MATLAB® integer type is to use the intmin and intmax functions as shown here for uint32:
intmin('uint32') intmax('uint32')
ans = ans =
0 4294967295double, single, int8, int16, int32, int64, intmax, intmin
![]() | Uimenu Properties | uiopen | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |