#include<stdio.h>int main(void)
{
int a = 70, c = 0;
int b = 1;
b = b << 3;
c = ~b;
a = a & c;
a += b;
printf("%d",a);
return0;
}
2.给定一个整形数a,设置a的bit3~bit7(为1),保持其他位不变。
#include<stdio.h>int main(void)
{
int a = 70, c = 0;
int b = 0b11111;
b = b << 3;
c = ~b;
a = a & c;
a += b;
printf("%d",a);
return0;
}
3.给定一个整型数a,清除a的bit15,保证其他位不变。
#include<stdio.h>int main(void)
{
int a = 70, c = 0;
int b = 1;
b = b << 15;
c = ~b;
a = a & c;
printf("%d",a);
return0;
}
4.给定一个整形数a,清除a的bit15~bit23,保持其他位不变。
#include<stdio.h>int main(void)
{
int a = 111111, c = 0;
int b = 0b111111111;
b = b << 15;
c = ~b;
a = a & c;
printf("%d",a);
return0;
}
5.给定一个整形数a,取出a的bit3~bit8。
#include<stdio.h>int main(void)
{
int a = 0, c = 0;
int b = 0b11111;
b = b << 3;
c = b & a;
c = c >> 3;
printf("%d",c);
return0;
}
6.用C语言给一个整形数的bit7~bit17赋值937(其余位不受影响)。
#include<stdio.h>int main(void)
{
int a = 0, c = 937;
int b = 0b11111111111;
c = b & c;
c = c << 7;
b = b << 7;
b = ~b;
a = a & b;
a += c;
printf("%d",a);
return0;
}
7.用C语言将一个整形数的bit7~bit17中的值加17(其余位不受影响)。
#include<stdio.h>int main(void)
{
int a = 0, c = 17;
c = c << 7;
a += c;
printf("%d",a);
return0;
}
8.用C语言给一个整形数的bit7~bit17赋值937,同时给bit21~bit25赋值17.
#include<stdio.h>int main(void)
{
int a = 0, c = 937;
int b = 0b11111111111;
c = b & c;
c = c << 7;
b = b << 7;
b = ~b;
a = a & b;
a += c;
c = 17;
c = c << 21;
a += c;
printf("%d",a);
return0;
}