Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.0.0 - English


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.

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 X decimal components have a fractional part, it is always trimmed to 0.

Example: int8([-3.6, -2.5, -1.4, 1.3, 3.5, 6.7]) // = [-3, -2, -1, 1, 3, 6].

Values of X components that are out of the targeted interval are wrapped (not saturated). Examples:

  • int8([127 128 129 130]) // = [127 -128 -127 -126].
  • uint8([254 255 256 257]) // = [254 255 0 1].

-%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 X is complex encoded, imaginary parts are ignored. Only the real parts are converted and returned.

[%f %t] is always converted into [0 1].

Converting big int64 or uint64 integers into decimal numbers may change them and downgrade their relative accuracy. Indeed, int64|uint64 integers are encoded over 63|64 bits, while the mantissa of decimal numbers is encoded over 53 bits only. For more details, please refer to the double() page.

Converting [] always keeps it as is, of type 1 (decimal type).

Functiony 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])
uint16([-1 %inf])
uint32([-1 %inf])
uint64([-1 %inf])
--> 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 - uint64(double(i))
--> 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

[] is not convertible:

i = uint16(3);
i(1,2) = 5.6
typeof(i)

i = uint16([])
i(1,2) = 2.3
typeof(i)
--> 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

  • iconvert — conversion to 1 to 8 byte integer representation
  • inttype — type integers used in integer data types
  • double — converts inttype integers or booleans into decimal encoding
  • dec2bin — convert from decimal to binary
  • dec2base — Convert decimal to base N number in string

History

VersionDescription
6.0
  • int64() and uint64() added to Scilab.
  • Complex input numbers are now accepted.
  • This is now instead of
    int8([-%inf, %inf])[-128, 127][0, 0]
    int16([-%inf, %inf])[-32768, 32767][0, 0]
    int32(%inf) 2147483647 -2147483648
    uint8(%inf) 255 0
    uint16(%inf) 65535 0
    uint32(%inf) 4294967295 0
Report an issue
<< iconvert Integers inttype >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Mar 27 11:52:42 GMT 2023