int8
conversion to one byte integer representation
int16
conversion to 2 bytes integer representation
int32
conversion to 4 bytes integer representation
int64
conversion to 8 bytes integer representation
uint8
conversion to one byte unsigned integer representation
uint16
conversion to 2 bytes unsigned integer representation
uint32
conversion to 4 bytes unsigned integer representation
uint64
conversion to 8 bytes unsigned integer representation
Syntax
y = int8(X) y = int16(X) y = int32(X) y = int64(X) y = uint8(X) y = uint16(X) y = uint32(X) y = uint64(X)
Arguments
- X
matrix of booleans, of encoded integers, or of decimal real or complex numbers. Matrix of strings representing literal big integers for
int64
anduint64
.- y
matrix of integers encoded on 1, 2, 4 or 8 bytes. Its sizes are X ones.
Description
These functions convert and store data to one, two, four, or eight bytes integers. These data types are especially useful to store big objects such as images, long signals,...
If some int8([-3.6, -2.5, -1.4, 1.3, 3.5, 6.7]) // = [-3, -2, -1, 1, 3, 6] .
Values of
-%inf is always converted into the lower bound of the interval (see below). %inf is always converted into the upper bound of the interval (see below). %nan is always converted into 0. If [%f %t] is always converted into [0 1]. |
Reading big literal integers with int64 or uint64:
Any input like |
Converting [] always keeps it as is, of type 1 (decimal type). |
Function | y in | = |
---|---|---|
int8(X) | [- 27, 27-1] | [-128, 127] |
int16(X) | [- 215, 215-1] | [-32768, 32767] |
int32(X) | [- 231, 231-1] | [-2147483648, 2147483647] |
int64(X) | [- 263, 263-1] | [-9223372036854775808, 9223372036854775807] |
uint8(X) | [0, 28-1] | [0, 255] |
uint16(X) | [0, 216-1] | [0, 65535] |
uint32(X) | [0, 232-1] | [0, 4294967295] |
uint64(X) | [0, 264-1] | [0, 18446744073709551615] |
Examples
Rounding to 0 and wrapping, and special values:
int8([-11.7 -8.5 -6.4 6.4 8.5 11.7]) int8([-130 -129 -128 -127 126 127 128 129]) a = -129 + 256*(-3:3) int8(a) int8([-%inf %inf %nan])
--> int8([-11.7 -8.5 -6.4 6.4 8.5 11.7]) ans = -11 -8 -6 6 8 11 --> int8([-130 -129 -128 -127 126 127 128 129]) ans = 126 127 -128 -127 126 127 -128 -127 --> a = -129 + 256*(-3:3) a = -897. -641. -385. -129. 127. 383. 639. --> int8(a) ans = 127 127 127 127 127 127 127 --> int8([-%inf %inf %nan]) ans = -128 127 0
About wrapping and upper bounds of unsigned integers:
--> uint8([-1 %inf]) ans = 255 255 --> uint16([-1 %inf]) ans = 65535 65535 --> uint32([-1 %inf]) ans = 4294967295 4294967295 --> uint64([-1 %inf]) ans = 18446744073709551615 18446744073709551615
Converting 64-bits integers into decimal numbers downgrades their accuracy:
--> i = uint64(2)^63 - 600 i = 9223372036854775208 --> i - uint64(double(i)) ans = 424
Converting booleans and complex numbers:
int8([%f %t]) int8(-10.2 + 3.4*%i) uint8(-10.2 + 3.4*%i)
--> int8([%f %t]) ans = 0 1 --> int8(-10.2 + 3.4*%i) ans = -10 --> uint8(-10.2 + 3.4*%i) ans = 246
Reading literal int64 or uint64 integers bigger than 2^53, without floating point truncation effect:
a = [uint64(1000000000000001000) ; uint64("1000000000000001000")] typeof(a) a = [int64(-1000000000000001000) ; int64("-1000000000000001000")] typeof(a)
--> a = [uint64(1000000000000001000) ; uint64("1000000000000001000")] a = 1000000000000001024 1000000000000001000 --> typeof(a) ans = "uint64" --> a = [int64(-1000000000000001000) ; int64("-1000000000000001000")] a = -1000000000000001024 -1000000000000001000 --> typeof(a) ans = "int64"
[] is not convertible:
--> i = uint16(3); --> i(1,2) = 5.6 i = 3 5 --> typeof(i) ans = uint16 --> i = uint16([]) i = [] --> i(1,2) = 2.3 i = 0. 2.3 --> typeof(i) ans = constant
See also
History
Version | Description | |||||||||||||||||||||
6.0 |
| |||||||||||||||||||||
6.1.2 | int64 and uint64 are extended to strings
to read big integers > 253 without truncation. |
Report an issue | ||
<< iconvert | Integers | inttype >> |