1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>INT8 Convert to Signed 8-bit Integer
</TITLE>
</HEAD>
<BODY>
<H2>INT8 Convert to Signed 8-bit Integer
</H2>
<P>
Section: <A HREF=sec_typecast.html> Type Conversion Functions </A>
<H3>Usage</H3>
Converts the argument to an signed 8-bit Integer. The syntax
for its use is
<PRE>
y = int8(x)
</PRE>
<P>
where <code>x</code> is an <code>n</code>-dimensional numerical array. Conversion
follows the saturation rules (e.g., if <code>x</code> is outside the normal
range for a signed 8-bit integer of <code>[-127,127]</code>, it is truncated to that
range. Note that
both <code>NaN</code> and <code>Inf</code> both map to 0.
<H3>Example</H3>
The following piece of code demonstrates several uses of <code>int8</code>. First, the routine uses
<PRE>
--> int8(100)
ans =
100
--> int8(-100)
ans =
-100
</PRE>
<P>
In the next example, an integer outside the range of the type is passed in.
The result is truncated to the range of the type.
<PRE>
--> int8(400)
ans =
127
</PRE>
<P>
In the next example, a positive double precision argument is passed in.
The result is the signed integer that is closest to the argument.
<PRE>
--> int8(pi)
ans =
3
</PRE>
<P>
In the next example, a complex argument is passed in. The result is the
signed complex integer that is closest to the argument.
<PRE>
--> int8(5+2*i)
ans =
5.0000 + 2.0000i
</PRE>
<P>
In the next example, a string argument is passed in. The string argument
is converted into an integer array corresponding to the ASCII values of each character.
<PRE>
--> int8('helo')
ans =
104 101 108 111
</PRE>
<P>
In the last example, a cell-array is passed in. For cell-arrays and
structure arrays, the result is an error.
<PRE>
--> int8({4})
Error: Cannot perform type conversions with this type
</PRE>
<P>
</BODY>
</HTML>
|