⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exerc.html

📁 C ++ in action
💻 HTML
字号:
<html>
<head>
    <title>Exercises</title>
    <link rel="stylesheet" href="../../rs.css">
</head>

<body background="../../images/margin.gif" bgcolor="#FFFFDC">

<!-- Main Table -->
<table cellpadding="6">
    <tr>
    <td width="78">
	&nbsp;
    <td>
    
<h3>Exercises</h3> 
<p>
In C++ one can perform bitwise operations on integral numbers. Binary bitwise operators AND and OR are denoted by ampersand & and vertical bar | respectively. The usage is
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>int i = 3;  // binary 0011
int j = 5;  // binary 0101
int k = i & j; // binary 0001
k = i | j;  // binary 0111
k = k | 8;  // binary 1111</pre>
</table>
<!-- End Code -->
<p>
Bitwise complement is denoted by a tilde ~. For instance (on a four-bit computer), if <i>k</i> = 13 (binary 1101) than its complement <i>j</i> = ~<i>k</i> would be equal to 2 (binary 0010) (ones become zeros and zeros become ones).
<p>
<table width=50% border=1>
<tr>
<td colspan=2><b>Binary Bitwise Operators</b>
<tr>
<td>&        <td>bitwise and
<tr>
<td>|        <td>bitwise (inclusive) or
<tr>
<td>^        <td>bitwise exclusive or (xor)
<tr>
<td>&gt;&gt;    <td>right shift by n bits
<tr>
<td>&lt;&lt;    <td>left shift by n bits
<tr>
<td colspan=2><b>Unary Bitwise Operator</b>
<tr>
<td>~        <td>one's complement
</table>

<ol>
<li>Add bitwise operations to our calculator.
<li>Add a new command, 'x', that toggles between decimal and hexadecimal outputs.
<p>To output a number in the hexadecimal (base sixteen) one sends a modifier "hex" to the output.
<!-- Code -->
<table width="100%" cellspacing=10><tr>
	<td class=codeTable>
<pre>using std::hex;
int i = 11;
cout &lt;&lt; hex &lt;&lt; i;   // i will be printed in hex as 'b'.</pre>
</table>
<!-- End Code -->
<li>Extend the calculator by adding <i>symbolic variables</i> denoted by lowercase letters. Add the assignment operation that assigns a value to a symbolic variable. For instance, one should be able to do the following
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>&gt; a
&gt; 5
&gt; =     // a = 5
&gt; 2
&gt; a
&gt; *    // 2 * 5</pre>
</table>
<!-- End Code -->

<p>
Consider what should the <var>Calculator</var> do with a symbol. For instance, what should it push on the stack?
</ol>


    
</table>
<!-- End Main Table -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -