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>
--> A = [2;5;6;2]
A =
2
5
6
2
--> 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
--> bin2int(B)
ans =
2
5
6
2
--> A = [1;2;-5;2]
A =
1
2
-5
2
--> 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
--> bin2int(B)
ans =
1
2
251
2
--> int32(bin2int(B))
ans =
1
2
251
2
</PRE>
<P>
<H3>Tets</H3>
</BODY>
</HTML>
|