zoukankan      html  css  js  c++  java
  • c#中位运算符的运用(转载)

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace weiyunsuan
    {
        class Program
        {
            static void Main(string[] args)
            {
                int x = 5;
                int y = 3;
                // & | ^ ~

                //&两个都是一才为1
                int z = x & y;
                //x=0101
                //y=0011
                //&-----------
                //z=0001(2)
                Console.WriteLine(z);

                //|两个有一个为一就为1
                z = x | y;
                //x=0101
                //y=0011
                //z=0111(7)
                Console.WriteLine(z);

                //^两个不同就为1
                z = x ^ y;
                //x=0101
                //y=0011
                //z=0110(6)
                Console.WriteLine(z);

                //~一元运算符相反值
                z = ~x;
                //x=0101
                //z=1010
                Console.WriteLine(z);

                z = x>>2;
                //x=0101
                //z=0001(1)
                Console.WriteLine(z);

                z = x << 2;
                //x=00010100
                //z=00010100
                Console.WriteLine(z);

                int x = 5;
                int y = 3;
                // & | ^ ~

                //&两个都是一才为1
                int z = x & y;
                //x=0101
                //y=0011
                //&-----------
                //z=0001(2)
                Console.WriteLine(z);

                //|两个有一个为一就为1
                z = x | y;
                //x=0101
                //y=0011
                //z=0111(7)
                Console.WriteLine(z);

                //^两个不同就为1
                z = x ^ y;
                //x=0101
                //y=0011
                //z=0110(6)
                Console.WriteLine(z);

                //~一元运算符相反值
                z = ~x;
                //x=0101
                //z=1010(-6)
                Console.WriteLine(z);


                z = x >> 2;
                //x=0101
                //z=0001(1)
                Console.WriteLine(z);

                z = x << 2;
                //x=00010100
                //z=00010100
                Console.WriteLine(z);

            }
        }
    }

  • 相关阅读:
    linux curses函数库
    在Android library中不能使用switch-case语句访问资源ID的原因分析及解决方案
    Android Support ;v4、v7、v13的区别
    background-position
    java web 之 web.xml篇
    javaweb之Cookie篇
    Enumeration 接口
    Java Bad version number in .class file
    使用AppCan自带的升级功能实现移动端升级
    obj.offsetHeight与obj.style.height区别
  • 原文地址:https://www.cnblogs.com/zpc870921/p/2662572.html
Copyright © 2011-2022 走看看