请教一个取反运算符的问题

lzh8430 2012-02-28 08:17:24
unsigned int t=0xff;
对t进行取反 结果是多少?为什么?多谢指点
...全文
124 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
AnYidan 2012-02-28
  • 打赏
  • 举报
回复
哪 个取反?

-
~

。。。。。。。。。。。。。。。。。
duke56 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lzh8430 的回复:]

引用 6 楼 duke56 的回复:
C/C++ code
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
//特别要注意一下编译是默认的int是多少位的
unsigned int i=0xFFFFFFFF;//我的编译int是32位
i=~i;
cout<<i<<endl……
[/Quote]
C++只是编译语言,并没有具体说int就是16位...int是多少位是由编译器决定的!
DNcx831 2012-02-28
  • 打赏
  • 举报
回复
用sizeof(t)可以看int的是几位的
DNcx831 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lzh8430 的回复:]

在c++里编译的引用 4 楼 dncx831 的回复:
要看int具体是几位的,16位:t = 0x00;32位:t = 0xff00;
[/Quote]
看平台,不看语言,如果你是用的vc6.0编写的,应该是32位的。
lzh8430 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 duke56 的回复:]
C/C++ code
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
//特别要注意一下编译是默认的int是多少位的
unsigned int i=0xFFFFFFFF;//我的编译int是32位
i=~i;
cout<<i<<endl;//输出……
[/Quote]
我定义变量一样的 位数自然是一样的了 unsigned int 在c++中是16位吧
muyi66 2012-02-28
  • 打赏
  • 举报
回复
int 是 4 个字节的,你才赋给了1个字节。结果取反之后是 0xFFFFFF00
duke56 2012-02-28
  • 打赏
  • 举报
回复
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
//特别要注意一下编译是默认的int是多少位的
unsigned int i=0xFFFFFFFF;//我的编译int是32位
i=~i;
cout<<i<<endl;//输出一个0
return 0;
}
lzh8430 2012-02-28
  • 打赏
  • 举报
回复
在c++里编译的[Quote=引用 4 楼 dncx831 的回复:]
要看int具体是几位的,16位:t = 0x00;32位:t = 0xff00;
[/Quote]
DNcx831 2012-02-28
  • 打赏
  • 举报
回复
要看int具体是几位的,16位:t = 0x00;32位:t = 0xff00;
lzh8430 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 duke56 的回复:]
引用 1 楼 programmingring 的回复:

0xff二进制是11111111取反就是00000000


++
[/Quote]void main(void)
{
unsigned int t1=0x00;
unsigned int t2=0xff;
if(t1==~t2)
cout<<"正确"<<endl;
else
cout<<"错误"<<endl;
}总是输出 “错误”
duke56 2012-02-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 programmingring 的回复:]

0xff二进制是11111111取反就是00000000
[/Quote]

++
ProgrammingRing 2012-02-28
  • 打赏
  • 举报
回复
0xff二进制是11111111取反就是00000000

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧