6

【笔记】C语言按位运算符

 1 year ago
source link: https://feiju12138.github.io/2022/11/04/C%E8%AF%AD%E8%A8%80%E6%8C%89%E4%BD%8D%E8%BF%90%E7%AE%97%E7%AC%A6/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【笔记】C语言按位运算符

2022-11-04C语言学习指北

1

C语言按位运算符

按位取反运算

  • 所有位取反
1001 1001
---------
0110 0110
num = ~num;

左移运算符

  • 左移1位,最低位补0
1001 1001
---------
0011 0010
num << 1;

右移运算符

  • 右移1位,最高位补0
1001 1001
---------
0100 1100
num >> 1;

按位与运算

  • 有0则0,全1为1
1001 1001
1010 1010
---------
1000 1000
num = num & 0b10101010;

按位或运算

  • 有1则1,全0则0
1001 1001
1010 1010
---------
1011 1011
num = num & 0b10101010;

按位异或运算

  • 不同为1,相同为0
1001 1001
1010 1010
---------
0011 0011
num = num ^ 0b10101010;

按位同或运算

  • 相同为1,不同为0
1001 1001
1010 1010
---------
1100 1100
# C

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK