File: typecast_bin2int.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 (93 lines) | stat: -rw-r--r-- 1,494 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
86
87
88
89
90
91
92
93
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
<TITLE>BIN2INT Convert Binary Arrays to Integer
</TITLE>
</HEAD>
<BODY>
<H2>BIN2INT Convert Binary Arrays to Integer
</H2>
<P>
Section: <A HREF=sec_typecast.html> Type Conversion Functions </A>
<H3>Usage</H3>
Converts the binary decomposition of an integer array back
to an integer array.  The general syntax for its use is
<PRE>
   y = bin2int(x)
</PRE>
<P>
where <code>x</code> is a multi-dimensional logical array, where the last
dimension indexes the bit planes (see <code>int2bin</code> for an example).
By default, the output of <code>bin2int</code> is unsigned <code>uint32</code>.  To
get a signed integer, it must be typecast correctly.  A second form for
<code>bin2int</code> takes a <code>'signed'</code> flag
<PRE>
   y = bin2int(x,'signed')
</PRE>
<P>
in which case the output is signed.
<H3>Example</H3>
The following piece of code demonstrates various uses of the int2bin
function.  First the simplest example:
<PRE>
--&gt; A = [2;5;6;2]

A = 
 2 
 5 
 6 
 2 

--&gt; B = int2bin(A,8)

B = 
 0 0 0 0 0 0 1 0 
 0 0 0 0 0 1 0 1 
 0 0 0 0 0 1 1 0 
 0 0 0 0 0 0 1 0 

--&gt; bin2int(B)

ans = 
 2 
 5 
 6 
 2 

--&gt; A = [1;2;-5;2]

A = 
  1 
  2 
 -5 
  2 

--&gt; B = int2bin(A,8)

B = 
 0 0 0 0 0 0 0 1 
 0 0 0 0 0 0 1 0 
 1 1 1 1 1 0 1 1 
 0 0 0 0 0 0 1 0 

--&gt; bin2int(B)

ans = 
   1 
   2 
 251 
   2 

--&gt; int32(bin2int(B))

ans = 
   1 
   2 
 251 
   2 
</PRE>
<P>
<H3>Tets</H3>
</BODY>
</HTML>