首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# 按位求补运算符解决办法

2012-03-16 
c# 按位求补运算符bytei0Console.WriteLine(~i)//为什么输出-1,不是应该输出255吗?[解决办法]返回int值

c# 按位求补运算符
byte   i=   0;                        
Console.WriteLine(~i);//为什么输出-1,不是应该输出255吗?

[解决办法]
返回int值...
----------
操作数byte返回int值...编译器会隐式转换它的类型...
[解决办法]
byte i = 0;
i = (byte)~i;
需要强制转换
[解决办法]
byte i = 0;

Console.WriteLine( "{0:x8} ", ~i);

输出是:

ffffffff

和Console.WriteLine用的Format 有关

热点排行