Last sync 2016.04.01
[deliverable/titan.core.git] / help / info / bitstring.html
1 <!--
2 Copyright (c) 2000-2016 Ericsson Telecom AB
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Eclipse Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/epl-v10.html
7
8 Contributors:
9 Baji, Laszlo
10 Balasko, Jeno
11 Csorba, Mate
12 Farkas, Laszlo
13 Forstner, Matyas
14 Szabados, Kristof
15 -->
16 <html>
17 <head>
18 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
19 <meta http-equiv="Content-Language" content="en-us">
20 <title>bitstring</title>
21 </head>
22 <body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258">
23 <table align="left" border="0" cellspacing="0" cellpadding="0" valign=top>
24 <tr>
25 <td width=105 height=40><a href="https://projects.eclipse.org/projects/tools.titan"><img src="../images/titan_transparent.gif" border=0 width=105 height=40 align="left" alt="Titan"></a></td>
26 </tr>
27 </table>
28 <table border="0" align="right" cellpadding="0" cellspacing="0">
29 <tr>
30 <td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td>
31 <td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td>
32 <td><a alt="previous" href="bit2str.html"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td>
33 <td><a href="boolean.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td>
34 </tr>
35 </table>
36 <p><br clear="all">
37 </p>
38 <hr>
39 <h1>bitstring</h1>
40 <hr align="left" width="75%">
41 <p>The keyword <b><font face="Courier New">bitstring</font></b> denotes a basic string type whose distinguished values are the ordered sequences of zero, one or more bits.</p>
42 <ul>
43 <li>Bit string values are written between <a href="#double_quotation"> single quotes and followed by the capital letter B.</a> (' 'B).</li>
44 <li>A bit string may be specified by its integer value using a <a href="#conversion">conversion function</a>.</li>
45 <li>The <a href="#relation">relational operators</a> equality (==) and non-equality (!=) can be used to compare values of two bit strings</li>
46 <li>The <a href="#shift">shift operators</a> perform the shift left (&lt;&lt;) and shift right (&gt;&gt;) operations.</li>
47 <li>The <a href="#rotate">rotate operators</a> perform the rotate left (&lt;@) and rotate right (@&gt;) operations.</li>
48 <li>The <a href="#concatenation"> concatenation operator</a> (&amp;) performs a simple concatenation from left to right.</li>
49 <li>Bitwise operators (<a href="and4b.html">and4b</a>, <a href="not4b.html">not4b</a>, <a href="or4b.html">or4b</a>, <a href="xor4b.html"
50 target="_blank">xor4b</a>) are used to manipulate bits in the string.</li>
51 <li>A <a href="#array"> single bit</a> may be accessed using an array-like syntax. The leftmost bit has the index zero.</li>
52 <li>The bit string may be <a href="#vacuum">empty</a>.</li>
53 <li>Predefined functions operating on bit strings:</li>
54 <ul>
55 <li><a href="#bit2hex">bit2hex</a> converts a bit string value to a hexadecimal string.</li>
56 <li><a href="#str2int">bit2int</a> converts a bit string to the equivalent integer.</li>
57 <li><a href="#str2oct">bit2oct</a> converts a bit string to an octet string.</li>
58 <li><a href="#bit2str">bit2str</a> converts a bit string to a character string.</li>
59 <li><a href="#lengthof">lengthof</a> returns an integer value indicating the number of bits in a string.</li>
60 </ul>
61 <li>The length of the bit string can be constrained using the keyword <a href="length.html"><b><font face="Courier New" color="#003258" size="4">length</font></b></a>.</li>
62 <li>Another way to limit the permitted values of a bit string is <a href="#list">to list them</a>.</li>
63 </ul>
64 <p>Related keywords:</p>
65 <ul>
66 <li><a href="bit2hex.html"><b><font face="Courier New" color="#003258" size="4">bit2hex</font></b></a></li>
67 <li><a href="bit2int.html"><b><font face="Courier New" color="#003258" size="4">bit2int</font></b></a></li>
68 <li><a href="bit2oct.html"><b><font face="Courier New" color="#003258" size="4">bit2oct</font></b></a></li>
69 <li><a href="bit2str.html"><b><font face="Courier New" color="#003258" size="4">bit2str</font></b></a></li>
70 <li><a href="hex2bit.html"><b><font face="Courier New" color="#003258" size="4">hex2bit</font></b></a></li>
71 <li><a href="int2bit.html"><b><font face="Courier New" color="#003258" size="4">int2bit</font></b></a></li>
72 <li><a href="length.html"><b><font face="Courier New" color="#003258" size="4">length</font></b></a></li>
73 <li><a href="lengthof.html"><b><font face="Courier New" color="#003258" size="4">lengthof</font></b></a></li>
74 <li><a href="oct2bit.html"><b><font face="Courier New" color="#003258" size="4">oct2bit</font></b></a></li>
75 <li><a href="str2bit.html"><b><font face="Courier New" color="#003258" size="4">str2bit</font></b></a></li>
76 <li><a href="substr.html"><b><font face="Courier New" color="#003258" size="4">substr</font></b></a></li>
77 <li><a href="and4b.html"><b><font face="Courier New" color="#003258" size="4">and4bit</font></b></a></li>
78 <li><a href="not4b.html"><b><font face="Courier New" color="#003258" size="4">not4bit</font></b></a></li>
79 <li><a href="or4b.html"><b><font face="Courier New" color="#003258" size="4">or4bit</font></b></a></li>
80 <li><a href="xor4b.html"><b><font face="Courier New" color="#003258" size="4">xor4bit</font></b></a></li>
81 </ul>
82 <hr align="left" width="50%">
83 <div align="center">
84 <center>
85 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
86 <tr>
87 <td width="100%">
88 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>bitstring</b></font></h3>
89 </td>
90 </tr>
91 </table>
92 </center>
93 </div>
94 <hr align="left" width="50%">
95 <p><a name="double_quotation">Example 1</a>:
96 <p><font face="Courier New">const bitstring c_bitfolyam := '01001'B;<br>
97 </font>
98 <p>The constant defined is called c_bitfolyam and has the binary value 01001.</p>
99 <hr align="left" width="50%">
100 <p><a name="conversion">Example 2</a>:
101 <p><font face="Courier New">const bitstring c_whole := int2bit (112,8);<br>
102 </font>
103 <p>The constant called c_whole will contain the string 01110000 because the converted integer number (112 -&gt; 1110000) must be coded on 8 bits and therefore padded with a leading zero.</p>
104 <hr align="left" width="50%">
105 <p><a name="relation">Example 3</a>:
106 <p><font face="Courier New">const boolean c_vrai := ( c_bitfolyam != c_whole );<br>
107 </font>
108 <p>The constant c_vrai will have the value true, because two bit strings are not equal. The parentheses are optional.</p>
109 <hr align="left" width="50%">
110 <p><a name="concatenation">Example 4</a>:
111 <p><font face="Courier New">const bitstring c_stick := c_bitfolyam &amp; c_whole;<br>
112 </font>
113 <p>The constant c_stick will have the binary value 0100101110000.</p>
114 <hr align="left" width="50%">
115 <p><a name="array">Example 5</a>:
116 <p><font face="Courier New">const bitstring c_jediny := c_bitfolyam[1];<br>
117 </font>
118 <p>The constant called c_jediny will have the binary value 1.</p>
119 <hr align="left" width="50%">
120 <p><a name="vacuum">Example 6</a>:
121 <p><font face="Courier New">const bitstring c_inget := ''B;<br>
122 </font>
123 <p>The constant called c_inget will be an empty string.</p>
124 <hr align="left" width="50%">
125 <p><a name="bit2hex">Example 7a</a>:
126 <p><font face="Courier New">const hexstring c_ganz := bit2hex ('111010111'B);</font><br>
127 <p>The constant called c_ganz will have the hexadecimal value 1D7. The bit string is divided in groups of four starting from the right and converted to hexadecimal digits. When the last group has
128 less than four bits it will be padded with leading zeros</p>
129 <hr align="left" width="50%">
130 <p><a name="str2int">Example 7b</a>:
131 <p><font face="Courier New">const integer c_samostatny := bit2int ('1111111'B);<br>
132 </font>
133 <p>The constant called c_samostatny will have the integer value 127. The result will be always positive.</p>
134 <hr align="left" width="50%">
135 <p><a name="str2oct">Example 7c</a>:
136 <p><font face="Courier New">const octetstring c_tre := bit2oct ('101001011010'B);<br>
137 </font>
138 <p>The constant called c_tre will have the value '0A5A'O .</p>
139 <hr align="left" width="50%">
140 <p><a name="bit2str">Example 7d</a>:
141 <p><font face="Courier New">const charstring c_bokstaever := bit2str ('101001011010'B);<br>
142 </font>
143 <p>The constant called c_bokstaever will contain the string 101001011010 because the resulting character string has the same length as the bit string and contains only the characters '0' and '1'.</p>
144 <hr align="left" width="50%">
145 <p><a name="lengthof">Example 7e</a>:
146 <p><font face="Courier New">const integer c_longeur := lengthof ('01001011010'B);<br>
147 </font>
148 <p>The constant called c_longeur will have the value 11 corresponding to the number of bits in the string .</p>
149 <hr align="left" width="50%">
150 <p><a name="list">Example 8</a>:
151 <p><font face="Courier New">var bitstring c_zabradli ('1010'B,'11'B,'011'B );<br>
152 </font>
153 <p>The variable called c_zabradli may assume the binary values 1010, 11, 011 only.</p>
154 <hr align="left" width="50%">
155 <p><a name="rotate">Example 9</a>:&nbsp;</p>
156 <p><font face="Courier New">const bitstring c_bithinta := '100001'B @&gt; 2;<br>
157 </font>
158 <p>The constant called c_bithinta will hold the value '011000'B (the left operand rotated by two bits).&nbsp;</p>
159 <hr align="left" width="50%">
160 <p><a name="shift">Example 10</a>:</p>
161 <p><font face="Courier New">const bitstring c_slippery := '111001'B &lt;&lt; 2;<br>
162 </font>
163 <p>The constant called c_slippery will hold the value ''100100'B (the left operand shifted by two bits).</p>
164 <hr align="left" width="25%">
165 <hr align="left" width="25%">
166 <p align="left"><a HREF="BNF.html#bitstringkeyword">BNF definition</a> of <font face="Courier New">bitstring</font><br>
167 <a HREF="BNF.html#bitstringvalue">BNF definition</a> of bitstring value</p>
168 </body>
169 </html>
This page took 0.039035 seconds and 6 git commands to generate.