- 浏览: 45443 次
-
文章分类
最新评论
位运算符|=
2^3 异或 0010 ^ 0011 0001
http://blog.csdn.net/vebasan/article/details/6193916
关于位运算讲解<wbr style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px"><div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
| 是位操作 || 是逻辑判断</div>
<div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
<div><img alt="位运算和逻辑运算 - ip - 人生是美好的" src="http://img0.ph.126.net/3MG5pK0d6IL7pjmenPqE6w==/6597330350912597442.jpg" style="border:0px; max-width:100%; margin:0px 10px 0px 0px"></div>
2.或操作对CRUD的权限进行控制的</div>
<div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
<div><img alt="位运算和逻辑运算 - ip - 人生是美好的" src="http://img2.ph.126.net/W2iY739xW5DUwx3hirtWdA==/6597586537122370349.jpg" style="border:0px; max-width:100%; margin:0px 10px 0px 0px"></div>
<div>aclState|=temp;===>aclState=aclState|temp<br>
</div>
</div>
<div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
<br>
</div>
<div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
3》101010|010101=111111</div>
<div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
<br>
</div>
<div style="line-height:28px; color:rgb(61,61,61); font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,u5b8bu4f53; font-size:16px">
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
*******</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<div class="dp-highlighter" id="" style="font-family:Monaco,'DejaVu Sans Mono','Bitstream Vera Sans Mono',Consolas,'Courier New',monospace; width:679px; overflow:auto; margin-left:9px; padding:1px; word-break:break-all; word-wrap:break-word; line-height:25.1875px">
<div class="bar">
<div class="tools" style="padding:3px; margin:0px; font-weight:bold">Java代码<a target="_blank" title="收藏这段代码" style="color:rgb(233,101,14); text-decoration:underline"><img class="star" src="http://renxiangzyq.iteye.com/images/icon_star.png" alt="收藏代码" style="border:0px"></a>
</div>
</div>
<ol start="1" class="dp-j" style="font-size:1em; line-height:1.4em; margin:0px 0px 1px; padding:2px 0px; border:1px solid rgb(209,215,220); list-style-position:initial; color:rgb(43,145,175)">
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">/**</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*设置操作</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*@parampermission哪一位</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*@paramyes允许或不允许</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*/</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">public</span><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">void</span>setPermission(<span class="keyword" style="color:rgb(127,0,85); font-weight:bold">int</span>permission,<span class="keyword" style="color:rgb(127,0,85); font-weight:bold">boolean</span>yes){</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//进行位运算</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">int</span>temp=<span class="number" style="color:rgb(192,0,0)">1</span>;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//移位00000100000100000010000001000</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">temp=temp<<permission;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">if</span>(yes){</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//目标是设置为可操作将操作为设置为1其他位不变</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//0|X=X1|X=1</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">aclState|=temp;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">}<span class="keyword" style="color:rgb(127,0,85); font-weight:bold">else</span>{</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//目标是设置为不可操作将操作为设置为0其他位不变</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//首先取反1111101111111101111111110111111111110111</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//0&X=01&X=X</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">aclState&=~temp;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">}</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">}</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">/**</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*查询某个位的开关</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*@parampermission哪一位</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*@return1表示允许0表示不允许-1表示不确定</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">*/</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">public</span><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">int</span>getPermission(<span class="keyword" style="color:rgb(127,0,85); font-weight:bold">int</span>permission){</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//0000001</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">int</span>temp=<span class="number" style="color:rgb(192,0,0)">1</span>;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//0000001000000010000000010000000001000</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">temp=temp<<permission;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//0&X=01&X=X只有当目标位不为0时即为1时temp才能为非0</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">temp=aclState&temp;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">if</span>(temp!=<span class="number" style="color:rgb(192,0,0)">0</span>){</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="comment" style="color:rgb(0,130,0); padding:0px; margin:0px; width:auto; border:0px">//说明为该操作位为1可执行</span></span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">return</span>ACL_YES;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">}</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black"><span class="keyword" style="color:rgb(127,0,85); font-weight:bold">return</span>ACL_NO;</span>
</li>
<li style="font-size:1em; margin:0px 0px 0px 38px; padding:0px 0px 0px 10px; border-left-width:1px; border-left-style:solid; border-left-color:rgb(209,215,220); background-color:rgb(250,250,250); line-height:18px">
<span style="color:black">}</span>
</li>
</ol>
</div>
<span style="font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px"></span>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:14px; line-height:25.1875px">
<span style="color:rgb(51,51,51); font-family:Verdana,'BitStream vera Sans',Tahoma,Helvetica,sans-serif; line-height:17px"></span></p>
<pre class="actionscript3" style="font-size:14px; line-height:25.1875px; background-color:rgb(255,255,255)"><span style="color:rgb(0,153,0)"><em>// 都是正数才管用的</em></span>
<span style="color:rgb(102,153,204)"><strong>var</strong></span> n<span style="color:rgb(0,0,102)"><strong>:</strong></span><span style="color:rgb(0,73,147)">int</span> = <span style="font-weight:bold">5</span><span style="color:rgb(0,0,102)"><strong>;</strong></span>
<span style="color:rgb(0,153,0)"><em>// 设置位 </em></span>
n <span style="color:rgb(0,0,102)"><strong>|</strong></span>= flag<span style="color:rgb(0,0,102)"><strong>;</strong></span>
<span style="color:rgb(0,153,0)"><em>// 取消位</em></span>
<span style="color:rgb(0,0,102)"><strong>~</strong></span>flag <span style="color:rgb(0,0,102)"><strong>&</strong></span> n<span style="color:rgb(0,0,102)"><strong>;</strong></span>
<span style="color:rgb(0,153,0)"><em>// 获取位</em></span>
n <span style="color:rgb(0,0,102)"><strong>&</strong></span> flag<span style="color:rgb(0,0,102)"><strong>;</strong></span></pre>
<br>
</div>
</wbr>
相关推荐
5.13_位运算符|Python的变量与运算符|Python3.8入门_&_进阶_&_原生爬虫实战完全解读
赋值运算符包括赋值运算符=、除后赋值运算符/=、乘后赋值运算符*=、取模后赋值运算符%=、加后赋值运算符+=、减后赋值运算符-=、左移后赋值运算符<<=、右移后赋值运算符>>=、按位与后赋值运算符&=、按位异或后赋值...
* 位选择运算符(bit-select):用于从一个信号中选择某些位,例如 `signal[3:0]`。 * 部分选择运算符(part-select):用于从一个信号中选择某些位,例如 `signal[3:1]`。 二、括号和逻辑非运算符 * 括号运算符...
本文将对C语言的运算符和表达式进行详细的介绍,包括运算符的概念、分类、优先级和结合性、算术运算符、自增和自减运算符、关系运算符、逻辑运算符、位运算符、赋值运算符、逗号运算符和条件运算符等。 一、引例 ...
6. 赋值运算符:包括赋值运算符=、加法赋值运算符+=、减法赋值运算符-=等,用于将值赋给变量。 7. 逗号运算符:包括逗号运算符,,用于将多个表达式连接成一个表达式。 二、javascript 运算符优先级 javascript ...
本文将详细介绍 C# 中的各种运算符和特殊符号的使用,包括一元运算符、二元运算符、赋值运算符、逻辑运算符、位运算符、关系运算符等。 一元运算符 * 正数作为一元运算符 +:表示正数,例如 `int mZhengshu = +1;`...
29. **赋值运算符=**:将右边的值赋给左边的变量,如`a = b`。 30. **除后赋值运算符/=,乘后赋值运算符*=,求余后赋值运算符%=,加后赋值运算符+=,减后赋值运算符-=,左移后赋值运算符<<=,右移后赋值运算符>>=,...
根据提供的文件信息,本篇文章将重点讲解Java中的运算符部分,包括算术运算符、赋值运算符、关系运算符、逻辑运算符、位运算符以及字符串连接运算符等内容,并结合实际例子进行深入剖析。 ### 3.4 运算符 #### ...
本文将详细介绍Python中常用的运算符及其用法,包括算术运算符、比较运算符、逻辑运算符、位运算符和成员运算符。 | 运算符 | 描述 | 示例 | | ------ | ---- | ---------- | | + | 加 | 3 + 5 = 8 | | - | 减 | 5 -...
首先,我们知道 | 和 & 定义为位运算符,|| 和 && 定义为逻辑运算符。 在区分之前,我们先要知道 | 与 & 的含义: & 按位与操作,按二进制位进行”与”运算。运算规则:(有 0 则为 0) | 按位或运算符,按二进制位...
赋值运算符包括赋值运算符=、除后赋值运算符/=、乘后赋值运算符*=、余数后赋值运算符%=、加后赋值运算符+=、减后赋值运算符-=等。这些运算符的优先级相对较低,总是被第十三个执行。 第十四和十五优先级:逗号...
C++中的运算符大致可以分为以下几类:赋值运算符、算术运算符、关系运算符、逻辑运算符、位运算符、成员访问运算符、自增自减运算符等。每个类别的运算符都有其特定的优先级。 1. 赋值运算符(如`=`, `+=`, `-=`等...
* 位运算符:&、|、^、~ * 条件运算符:?:、instanceof Java 运算符的优先级从高到低依次是: 1. 后缀运算符:()、[]、.、++ 2. 一元运算符:+、-、!、~ 3. 乘除运算符:*、/、% 4. 加减运算符:+、- 5. 移位...
通过上述介绍可以看出,逻辑运算符和位运算符在C语言中扮演着非常重要的角色。逻辑运算符用于组合条件表达式,而位运算符则用于对整数进行位级别的操作。掌握这两种运算符的用法有助于编写更高效、更灵活的程序。
~ 按位取反运算符 ~表达式 单目运算符 Sizeof 长度运算符 sizeof(表达式) 3 / 除 表达式/表达式 左到右 双目运算符 * 乘 表达式*表达式 双目运算符 % 余数(取模) 整型表达式%整型表达式 双目运算符 4 + 加 ...
9. **按位移位运算符** `和 `>>`: - 左移 `a 将二进制位向左移动b位。 - 右移 `a >> b`:将二进制位向右移动b位。 10. **关系运算符** `、`<=`、`>` 和 `>=`: - 小于 `a 。 - 小于等于 `a <= b`。 - 大于 `a...
8. **位移运算符** `<< >>`:位左移和位右移,常用于位操作。 9. **比较运算符** `< <= > >=` 和 **相等运算符** `== !=`:用于比较两个表达式的大小或是否相等。 10. **按位与** `&`、**按位异或** `^` 和 **按位或...
位运算符主要有六种:按位与(&),按位或(|),按位异或(^),按位取反(~),左移()和右移(>>). 1. **按位与(&)**: 这个运算符用于逐位比较两个二进制数,如果对应位置都是1,则结果位为1,否则为0。它常用于将某些位清...
### 使用位运算符实现数的逆转 在计算机科学领域,位运算符被广泛应用于各种算法优化及特定场景下的数据处理中。位运算符的操作对象是整数,在内存中以二进制形式存在,通过对这些二进制位进行操作来达到高效处理...
| 位运算符 | & ^ | | | 1 & 2 1 ^ 2 1 | 2 | 9 10 11 | 左结合性 | | 逻辑运算符 | && || ! | x && y x || y !x | 12 13 3 | 左结合性 | #### 三、详细说明 ##### 1. 后增量、后减量运算符 这些运算符(`++` 和 `...