Scilab 6.1.0
Change language to:
English - Français - Português - Русский

See the recommended documentation of this function

1バイト整数形式に変換する

2バイト整数形式に変換する

4バイト整数形式に変換する

8バイト整数形式に変換する

# uint8

1バイト符号なし整数形式に変換する

# uint16

2バイト符号なし整数形式に変換する

# uint32

4バイト符号なし整数形式に変換する

# uint64

8バイト符号なし整数形式に変換する

### 呼び出し手順

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

### パラメータ

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.

### 説明

1,2,4または8バイト整数に変換,保存します. これらのデータ型は画像,長い信号,...など大きなオブジェクトを 保存する際に特に有用です.

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]

### 例

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

### 参照

• iconvert — 1または8バイト整数表現に変換する
• inttype — 整数データ型で使用される整数型
• double — converts inttype integers or booleans into decimal encoding
• dec2bin — 10進数から2進数への変換
• dec2base — 10進数を基底Nの数値（文字列）に変換

### 履歴

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