Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Português


int8

conversão para representação de inteiro de 1 byte

int16

conversão para representação de inteiro de 2 bytes

int32

conversão para representação de inteiro de 4 bytes

int64

conversão para representação de inteiro de 8 bytes

uint8

conversão para representação de inteiro de 1 byte sem sinal

uint16

conversão para representação de inteiro de 2 bytes sem sinal

uint32

conversão para representação de inteiro de 4 bytes sem sinal

uint32

conversão para representação de inteiro de 8 bytes sem sinal

Seqüência de Chamamento

y = int8(X)
y = int16(X)
y = int32(X)
y = int64(X)
y = uint8(X)
y = uint16(X)
y = uint32(X)
y = uint64(X)

Parâmetros

X

matriz de booleanos, de inteiros codificados, ou de números reais ou complexos decimais. Matrix of strings representing literal big integers for int64 and uint64.

y

matriz de inteiros codificados em 1, 2, 4 ou 8 bytes. Seus tamanhos são os de X.

Descrição

Converte e armazena dados em interos de 1, 2 ou 4 bytes. Estes tipos de dados são especialmente úteis para armazenar objetos grandes como imagens, sinais longos,...

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].

Reading big literal integers with int64 or uint64: Any input like int64(1000000000000000000) implicitly considers 1000000000000000000 as a decimal integer whose mantissa is encoded with only 53 bits < 64 bits. Hence, this mantissa is most often truncated, and the encoded integer we get after the floating point truncation is not the input one. To avoid this effect, the integer can be provided as a string: int64("1000000000000000000") returns the expected integer, without loss of accuracy. For more details about truncation effect for big integers, 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]

Exemplos

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

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
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

Ver Também

  • iconvert — conversão para representação inteira de 1 a 8 bytes
  • inttype — tipos de dados inteiros
  • double — converts inttype integers or booleans into decimal encoding
  • dec2bin — representação binária
  • dec2base — Convert decimal to base N number in string

Histórico

VersãoDescrição
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
6.1.2 int64 and uint64 are extended to strings to read big integers > 253 without truncation.
Report an issue
<< iconvert Inteiros 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 Jun 17 17:53:23 CEST 2024