14
15
* along with this program.
17
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="bitget" xml:lang="en">
18
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
19
xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml"
20
xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
21
xmlns:scilab="http://www.scilab.org"
22
xml:id="bitget" xml:lang="en">
19
24
<refname>bitget</refname>
20
<refpurpose>bit at specified position</refpurpose>
25
<refpurpose>Extracts from integers bits of given indices</refpurpose>
23
28
<title>Syntax</title>
29
34
<title>Parameters</title>
35
a <literal>m</literal>-by-<literal>n</literal> matrix of doubles
36
or a <literal>m1</literal>-by-<literal>m2</literal>-by-...-by-<literal>mm</literal> hypermatrix of doubles
37
or a <literal>m</literal>-by-<literal>n</literal> matrix of unsigned integers (<literal>uint8</literal>, <literal>uint16</literal> or <literal>uint32</literal>).
38
Must contain positive integer values.
46
a <literal>m</literal>-by-<literal>n</literal> matrix of doubles
47
or a <literal>m1</literal>-by-<literal>m2</literal>-by-...-by-<literal>mm</literal> hypermatrix of doubles
48
or a <literal>m</literal>-by-<literal>n</literal> matrix of unsigned integers (<literal>uint8</literal>, <literal>uint16</literal> or <literal>uint32</literal>).
49
The input <varname>pos</varname> must be in the range 1, 2, ..., <literal>bitmax</literal>
50
where <literal>bitmax</literal> is the maximum number of bits in <varname>x</varname>.
51
Must contain positive integer values.
59
a <literal>m</literal>-by-<literal>n</literal> matrix of doubles
60
or a <literal>m1</literal>-by-<literal>m2</literal>-by-...-by-<literal>mm</literal> hypermatrix of doubles
61
or a <literal>m</literal>-by-<literal>n</literal> matrix of unsigned integers.
40
Scalar, vector, matrix or hypermatrix of positive decimal or encoded integers.
48
Scalar, vector, matrix or hypermatrix of decimal or encoded integers in
49
<literal>[1, bitmax]</literal> where <literal>bitmax</literal> is the
50
maximal index of bits for the type of <varname>x</varname>: Indices of bits
51
to be extracted. The bit #1 is the lightest one (2<superscript>0</superscript>).
53
<tr><th>typeof(x)</th><th>bitmax</th><td>..</td><th>typeof(x)</th><th>bitmax</th></tr>
54
<tr align="center"><td>int8 </td><td>7</td> <td> </td><td>uint8</td><td>8</td></tr>
55
<tr align="center"><td>int16 </td><td>15</td><td> </td><td>uint16</td><td>16</td></tr>
56
<tr align="center"><td>int32 </td><td>31</td><td> </td><td>uint32</td><td>32</td></tr>
57
<tr align="center"><td>int64 </td><td>63</td><td> </td><td>uint16</td><td>64</td></tr>
58
<tr align="center"><td>decimal</td><td>1024</td><td> </td><td></td><td></td></tr>
67
Scalar, vector, matrix or hypermatrix of 0 and 1 of the type of
68
<varname>x</varname>. The sizes and contents of <varname>y</varname> are
73
If <varname>x</varname> is a scalar:
76
<varname>y</varname> has the sizes of <varname>pos</varname>
79
<literal>y(i,j,..)</literal> is the value of bit
80
#<literal>pos(i,j,..)</literal> of <varname>x</varname>.
87
If <varname>pos</varname> is a scalar:
90
<varname>y</varname> has the sizes of <varname>x</varname>
93
<literal>y(i,j,..)</literal> is the value of the bit
94
#<literal>pos</literal> of <literal>x(i,j,..)</literal>.
101
If <varname>x</varname> and <varname>pos</varname> are arrays with
102
identical sizes, the processing is element-wise:
105
<varname>y</varname> has the sizes of <varname>x</varname>
106
and <varname>pos</varname>
109
<literal>y(i,j,..)</literal> is the value of the bit
110
#<literal>pos(i,j,..)</literal> of <literal>x(i,j,..)</literal>.
119
<varname>y</varname> is a matrix with
120
<literal>length(x)</literal> rows and
121
<literal>length(pos)</literal> columns.
124
<literal>y(i,j)</literal> is the value of the bit
125
#<literal>pos(j)</literal> of <literal>x(i)</literal>.
68
137
<title>Description</title>
70
Given an unsigned integer <varname>x</varname>, this function returns an unsigned integer <varname>y</varname>
71
(<literal>0</literal> or <literal>1</literal>) which is the bit number <varname>pos</varname> from the representation binary of <varname>x</varname>.
139
<literal>bitget()</literal> scans chosen bits of the binary representation of some
140
positive integers <varname>x</varname>. It returns 0 for bits down, and 1 for bits up.
143
The result has the sizes of <varname>x</varname> or of <varname>pos</varname> or
147
However, when both <varname>x</varname> and <varname>pos</varname> are non-scalar and
148
have mismatching sizes, the result <varname>y</varname> is a matrix ignoring the sizes
149
of <varname>x</varname>. Then, after reshaping <varname>y</varname> with
150
<literal>y = matrix(y, [size(x) -1])</literal>, the value of the bit #b of
151
<literal>x(i,..,k)</literal> is in <literal>y(i,..,k,b)</literal>.
86
166
bitget(uint8(13),4:-1:1)
88
// The input x can be a positive double
169
<emphasis role="bold">With arrays and encoded integers:</emphasis>:
171
<programlisting role="example"><![CDATA[
177
<emphasis role="bold">With big decimal integers > 2<superscript>52</superscript></emphasis>:
179
<programlisting role="example"><![CDATA[
180
x = sum(2 .^([7 16 18 19 25 52 70]-1))
181
bitget(x, [7 16 18 19 35 52 70 80])
184
--> x = sum(2 .^([7 16 18 19 25 52 70]-1))
188
--> bitget(x, [7 16 18 19 35 52 70 80])
190
Nan Nan 1. 1. 0. 1. 1. 0.
193
<emphasis role="bold">x and pos are arrays with mismatching sizes:</emphasis>
195
<programlisting role="example"><![CDATA[
196
x = [39 8 4 44 52 5 6 14 64 39 12 4 62 29 12 50 39 29];
208
bitget(x, [5 8 12 39])
211
--> bitget(x, [5 8 12 39])
221
<refsection role="see also">
222
<title>See Also</title>
223
<simplelist type="inline">
225
<link linkend="bitset">bitset</link>
228
<link linkend="bitand">bitand</link>
231
<link linkend="dec2bin">dec2bin</link>
234
<link linkend="and_op">&</link>
238
<refsection role="history">
239
<title>History</title>
242
<revnumber>6.1</revnumber>
246
Positive unsigned integers are now accepted.
249
64 bits encoded integers are now accepted.
252
For decimal integers, bits with index in [53, 1024] can now be retrieved.
255
For decimal integers > 2<superscript>52</superscript>, querying bits
256
below the <literal>%eps</literal> relative accuracy now returns
257
<literal>NaN</literal> instead of 0.
260
It is now possible to retrieve several bits from each component of