首页 >后端开发 >php教程 >PHP之与或非

PHP之与或非

WBOY
WBOY原创
2016-07-29 09:04:195046浏览

在程序运算中,数值都是转换成机器码(二进制)再进行加的,而与或非就是建立这这种基础上,以二进制进行运算。
$
1$0=0
或 |
1|0=1
非 ~
~1=0

<code><span><?php </span><span>//四个变量分别代表四盏灯的开关</span><span>$l_one</span> = <span>1</span>;
<span>$l_two</span> = <span>2</span>;
<span>$l_three</span> = <span>4</span>;
<span>$l_four</span> = <span>8</span>;
<span>//$sta代表四盏灯的状态</span><span>$sta</span> = <span>3</span>;
<span>//输出灯开的号码</span>
light_sta(<span>$sta</span>);
<span>//若要开启第四盏灯</span><span>echo</span><span>'开启第四盏灯:'</span>;
<span>$sta_n</span> = <span>$sta</span>|<span>$l_four</span>;
light_sta(<span>$sta_n</span>);

<span>//若要关闭第一盏灯</span><span>echo</span><span>'关闭第一盏灯:'</span>;
<span>$sta_o</span> = <span>$sta</span>&~<span>$l_one</span>;
light_sta(<span>$sta_o</span>);

<span>//输出灯开的号码</span><span><span>function</span><span>light_sta</span><span>(<span>$sta</span>)</span>{</span><span>//四个变量分别代表四盏灯的开关</span><span>$l_one</span> = <span>1</span>;
    <span>$l_two</span> = <span>2</span>;
    <span>$l_three</span> = <span>4</span>;
    <span>$l_four</span> = <span>8</span>;

    <span>echo</span><span>'light on: '</span>;
    <span>if</span>(<span>$sta</span>&<span>$l_one</span>){
        <span>echo</span><span>'1 '</span>;
    }<span>if</span>(<span>$sta</span>&<span>$l_two</span>){
        <span>echo</span><span>'2 '</span>;
    }<span>if</span>(<span>$sta</span>&<span>$l_three</span>){
        <span>echo</span><span>'3 '</span>;
    }<span>if</span>(<span>$sta</span>&<span>$l_four</span>){
        <span>echo</span><span>'4'</span>;
    }
    <span>echo</span><span>''</span>;
}</span></code>

PHP之与或非

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP之与或非,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn