File: typecast_uint16.html

package info (click to toggle)
freemat 4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 174,756 kB
  • ctags: 67,023
  • sloc: cpp: 351,059; ansic: 255,892; sh: 40,590; makefile: 4,387; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (85 lines) | stat: -rw-r--r-- 2,027 bytes parent folder | download | duplicates (2)
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
84
85
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
<TITLE>UINT16 Convert to Unsigned 16-bit Integer
</TITLE>
</HEAD>
<BODY>
<H2>UINT16 Convert to Unsigned 16-bit Integer
</H2>
<P>
Section: <A HREF=sec_typecast.html> Type Conversion Functions </A>
<H3>Usage</H3>
Converts the argument to an unsigned 16-bit Integer.  The syntax
for its use is
<PRE>
   y = uint16(x)
</PRE>
<P>
where <code>x</code> is an <code>n</code>-dimensional numerical array.  Conversion
follows saturation rules (e.g., if <code>x</code> is outside the normal
range for an unsigned 16-bit integer of <code>[0,65535]</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>uint16</code>.
<PRE>
--&gt; uint16(200)

ans = 
 200 
</PRE>
<P>
In the next example, an integer outside the range  of the type is passed in.  
The result is truncated to the maximum value of the data type.
<PRE>
--&gt; uint16(99400)

ans = 
 65535 
</PRE>
<P>
In the next example, a negative integer is passed in.  The result is 
truncated to zero.
<PRE>
--&gt; uint16(-100)

ans = 
 0 
</PRE>
<P>
In the next example, a positive double precision argument is passed in.  
The result is the unsigned integer that is closest to the argument.
<PRE>
--&gt; uint16(pi)

ans = 
 3 
</PRE>
<P>
In the next example, a complex argument is passed in.  The result is the 
complex unsigned integer that is closest to the argument.
<PRE>
--&gt; uint16(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>
--&gt; uint16('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>
--&gt; uint16({4})
Error: Cannot perform type conversions with this type
</PRE>
<P>
</BODY>
</HTML>