【程序51】
题目:学习使用按位与 & 。
1.程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1
2.程序源代码:
#include "stdio.h"
main()
{
int a,b;
a=077;
b=a&3;
printf("\40: The a & b(decimal) is %d \n",b);
b&=7;
printf("\40: The a & b(decimal) is %d \n",b);
}
==============================================================
【程序52】
题目:学习使用按位或 | 。
1.程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1
2.程序源代码:
#include "stdio.h"
main()
{
int a,b;
a=077;
b=a|3;
printf("\40: The a & b(decimal) is %d \n",b);
b|=7;
printf("\40: The a & b(decimal) is %d \n",b);
}
==============================================================
【程序53】
题目:学习使用按位异或 ^ 。
1.程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0
2.程序源代码:
#include "stdio.h"
main()
{
int a,b;
a=077;
b=a^3;
printf("\40: The a & b(decimal) is %d \n",b);
b^=7;
printf("\40: The a & b(decimal) is %d \n",b);
}
==============================================================
【程序54】
题目:取一个整数a从右端开始的4~7位。
程序分析:可以这样考虑:
(1)先使a右移4位。
经典c程序100例==51--60
本文介绍了C语言中位操作的经典实例,包括按位与(&), 按位或(|), 按位异或(^)的使用,以及位取反(~)、移位等操作的演示。通过多个示例代码,阐述了如何在实际编程中应用这些位操作技巧,例如提取整数的特定位和画图等。"
105523215,9448284,Lua中的算术与关系运算,['lua'],"['Lua', '算术运算符', '关系运算符', '编程', '学习笔记']

最低0.47元/天 解锁文章
2193

被折叠的 条评论
为什么被折叠?



