先上代码
// 10191.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
int main()
{
char x=0xfe;
int y=x>>1;
printf("%d",y);
}
x是有符号类型,x=1111 1110
那么x>>1=1111 1111
由于是有符号类型的数据,所以y=-1
那么在c语言中,右移是算术右移
// 10192.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
int main()
{
char x=0x0e;
int y=x>>1;
printf("%d",y);
}
x=0xe=0000 1110
那么x>>1=0000 0111=7
本文通过两个具体的C语言代码示例,详细解析了位右移运算符在不同数值下的表现,展示了有符号整数在进行位操作时的特殊处理方式。

4361

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



