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

📄 047-050.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Java Programming: The Basics</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=2//-->
<!--PAGES=047-050//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="045-047.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="050-054.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Operators</FONT></H4>
<P>Java has assignment operators like those of most other languages. There are also the shortcut operators of C and C&#43;&#43;. Here is a typical assignment operator followed by the shortcut version common to C, C&#43;&#43;, and Java:
</P>
<!-- CODE SNIP //-->
<PRE>
i = i &#43; 1;
i&#43;&#43;;
</PRE>
<!-- END CODE SNIP //-->
<P>Both versions have the same effect. The &#43; operator is a binary operator, because it takes two arguments. The &#43;&#43; operator is a unary operator, because it takes only one argument. The Unary operators are &#43;, -, &#43;&#43;, ~,!.
</P>
<P>Unary operators group right-to-left, so that the following two statements mean the same thing:</P>
<!-- CODE SNIP //-->
<PRE>
-!i
-(!i).
</PRE>
<!-- END CODE SNIP //-->
<P>The MBNF for the Java operators follows:
</P>
<!-- CODE SNIP //-->
<PRE>
Operator -&gt;  &#147;=&#147; | &#147;&gt;&#147; | &#147;&lt;&#147; | &#147;!&#148; | &#147;~&#148; | &#147;?&#148; | &#147;:&#148; | &#147;==&#147; | &#147;&lt;=&#147; | &#147;&gt;=&#147; |
&#147;!=&#147; |
     &#147;&#38;&#38;&#148; | &#147;||&#148; | &#147;&#43;&#43;&#148; | &#147;&#151;&#148; | &#147;&#43;&#148; | &#147;-&#148; | &#147;*&#148; | &#147;/&#148; | &#147;&#38;&#148; | &#147;|&#148; | &#147;^&#148; |
&#147;%&#148; |
     &#147;&lt;&lt;&#147; | &#147;&gt;&gt;&#147; | &#147;&gt;&gt;&gt;&#147; | &#147;&#43;=&#147; | &#147;-=&#147; | &#147;*=&#147; | &#147;/=&#147; | &#147;&#38;=&#147; | &#147;|=&#147; | &#147;^=&#147; |
     &#147;%=&#147; | &#147;&lt;&lt;=&#147;.
</PRE>
<!-- END CODE SNIP //-->
<P>In Java, you can have prefix unary operators:
</P>
<!-- CODE SNIP //-->
<PRE>
&#43;&#43;i;
</PRE>
<!-- END CODE SNIP //-->
<P>You can also use postfix unary operators:
</P>
<!-- CODE SNIP //-->
<PRE>
i&#43;&#43;;
</PRE>
<!-- END CODE SNIP //-->
<P>Unary operators work just like their C counterparts. The order of precedence is listed next, along with the <SMALL>MBNF</SMALL>.</P>
<!-- CODE //-->
<PRE>
postfix_operators-&gt;
            &#147;[]&#148; | &#147;.&#148; | &#147;(&#147; &lt;parameters&gt; &#147;)&#148; | &#147;&#43;&#43;&#148; | &#147;&#151;&#148; .
unary_operators -&gt;
           &#147;&#43;&#148;| &#147;-&#148; | &#147;&#43;&#43;&#148; | &#147;&#151;&#148; | &#147;~&#148; | &#147;!&#148; .
creation_operators-&gt;
            &#147;new&#148; | &#147;(&#147; &lt;type&gt; &#147;)&#148; .
multiplicative_operators-&gt;
            &#147;*&#148; | &#147;/&#148; | &#147;%&#148;. additive_operators -&gt; &#147;&#43;&#148; | &#147;-&#148;.
shift_operators -&gt;
            &#147;&lt;&lt;&#148; | &#147;&gt;&gt;&#147; | &#147;&gt;&gt;&gt;&#147;.
relational_operators -&gt;
            &#147;&lt;&#148; | &#147;&gt;&#148; | &#147;&gt;=&#148; | &#147; &lt;=&#148; | &#147;instanceof&#148; .
equality_operators -&gt;
            &#147;==&#148; | &#147;!=&#148; . bitwise_AND_operator  -&gt; &#147;&#38;&#148; .
bitwise_XOR -&gt;
            &#147;^&#148; . bitwise_OR -&gt; &#147;|&#148; .
logical_AND -&gt; &#147;&#38;&#38;&#148; .
logical_OR -&gt;
            &#147;||&#148; .
conditional_operator -&gt;
            &#147;?:&#148; .
assignment_operators -&gt;
            &#147;=&#148; | &#147;&#43;=&#148; | &#147; -=&#148;
            | &#147;*=&#148; | &#147;/=&#148; | &#147;%=&#148; | &#147;&gt;&gt;=&#148; |
            &#147;&lt;&lt;=&#148; | &#147;&gt;&gt;&gt;=&#148; | &#147;&#38;=&#148;  | &#147;^=&#148;  | &#147;|=&#148;.
</PRE>
<!-- END CODE //-->
<P>It is a part of the C idiom that assignment operators be augmented with other operators. We will give examples of the augmented operators, &#147;&#43;=&#148; , &#147; -=&#148; , &#147;*=&#148; , &#147;/=&#148; , &#147;%=&#148; , &#147;&gt;&gt;=&#148; , &#147;&lt;&lt;=&#148; , &#147;&gt;&gt;&gt;=&#148; , &#147;&#38;=&#148; , &#147;^=&#148; and &#147;|=&#148;,as well as the condition operator, because they are the most commonly misused by our students.
</P>
<P>Consider this example:</P>
<!-- CODE SNIP //-->
<PRE>
if (theCowsComeHome) &#123;System.out.println(&#147;moo&#148;);&#125;
     else System.out.println(&#147;no milk for you!&#148;);
</PRE>
<!-- END CODE SNIP //-->
<P>It is the same as the following:
</P>
<!-- CODE SNIP //-->
<PRE>
System.out.println(
     theCowsComeHome ? &#147;moo&#148; : &#147;no milk for
      you!&#148;);
</PRE>
<!-- END CODE SNIP //-->
<P>So the conditional operator requires a Boolean type expression followed by an expression to return if true with a :, and then an expression to return if false.
</P>
<P>Here are some examples of the augmented operators with their non-augmented counterparts:</P>
<!-- CODE //-->
<PRE>
i *= 10; // is the same as:

i = i * 10;
i &#43;= 10; // is the same as:
i = i &#43; 10;
i /= 10; // is the same as:
i = i / 10;
i &gt;&gt;= 3; // is the same as:
i = i &gt;&gt; 3; // a right shift with sign in the extension
i &gt;&gt;&gt;= 9; // is the same as:

i = i &gt;&gt;&gt; 9; // a right shift with zeros in the extension
</PRE>
<!-- END CODE //-->
<P>The following code example will reverse the bits in an int. Bit reversal code is used to perform transforms such as the Fast Hartley Transform (FHT) and the Fast Fourier Transform (FFT):
</P>
<!-- CODE SNIP //-->
<PRE>
 int bitr(int j) &#123;
      int ans = 0;
      for (int i = 0; i&lt; nu; i&#43;&#43;) &#123;
           ans = (ans &lt;&lt;1) &#43; (j&#38;1);
           j = j&gt;&gt;1;
      &#125;
      return ans; &#125;
</PRE>
<!-- END CODE SNIP //-->
<P>The variable <I>nu</I> is declared as an int and is equal to the number of bits to be processed. It is common to replace such bit shifting code with lookup tables that group the bits into 8- or 16-bit groups.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="045-047.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="050-054.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

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