# C操作符練習

#include <stdio.h>

#define PRINT(int) printf(#int " = %d\n",int)

int main(void)

{

int x,y,z;

/*

優先順序：位元運算符中：& > |

位元運算符& > 邏輯運算子&&

*/

x = 03; y = 02; z = 01;

PRINT(x | y & z); //0011 | 0000 = 3

PRINT(x | y & ~ z); //0011 | 0010 = 3

PRINT(x ^ y & ~ z); //0011 ^ 0010 = 1

PRINT(x & y && z); //2 && 1 = 1

x = 1; y = -1;

PRINT(! x | x);  //((!x) | x)=false | x = 1

// http://www.bianceng.cn

PRINT(~ x | x);  //1111 = -1

PRINT(x ^ x);  //0001 ^ 0001 = 0

x <<= 3;PRINT(x); //左移n位效果上看成乘以n個2 = 8

y <<= 3;PRINT(y); //………………………………&hellip ;= -8

y >>= 3;PRINT(y); //右移n位效果上看成除以n個2 = -1

return 0;

}

x | y & z = 3

x | y & ~ z = 3

x ^ y & ~ z = 1

x & y && z = 1

! x | x = 1

~ x | x = -1

x ^ x = 0

x = 8

y = -8

y = -1

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD