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>
位运算符|=
最新推荐文章于 2023-05-16 21:31:57 发布