using System;
class Test
{ public static void Main() {
byte a = 10;
sbyte b = 10;
short c = 10;
ushort d = 10;
int e = 10;
uint f = 10;
long g = 10;
ulong h = 10;
Console.WriteLine("byte: {0}",~a);
Console.WriteLine("sbyte: {0}",~b);
Console.WriteLine("short: {0}",~c);
Console.WriteLine("ushort: {0}",~d);
Console.WriteLine("int: {0}", ~e);
Console.WriteLine("uint: {0}", ~f);
Console.WriteLine("long: {0}", ~g);
Console.WriteLine("ulong: {0}", ~h);
}
}
运算结果为:
-11
-11
-11
-11
-11
4294967285
-11
18446744073709551605为什么是这个结果,为什么??????
class Test
{ public static void Main() {
byte a = 10;
sbyte b = 10;
short c = 10;
ushort d = 10;
int e = 10;
uint f = 10;
long g = 10;
ulong h = 10;
Console.WriteLine("byte: {0}",~a);
Console.WriteLine("sbyte: {0}",~b);
Console.WriteLine("short: {0}",~c);
Console.WriteLine("ushort: {0}",~d);
Console.WriteLine("int: {0}", ~e);
Console.WriteLine("uint: {0}", ~f);
Console.WriteLine("long: {0}", ~g);
Console.WriteLine("ulong: {0}", ~h);
}
}
运算结果为:
-11
-11
-11
-11
-11
4294967285
-11
18446744073709551605为什么是这个结果,为什么??????
解决方案 »
- C#用System.Net.Mail发送邮件时的所谓SMTP服务器需要身份验证,是指什么,代码如何写,请举个例子
- 大家有做音频压缩的吗?都来说说难不难
- WinForm中文本框,怎么样不让用Ctrl+V进行操作呢?
- 关于自定义内存表绑定DataGridViewComboBoxColumn的问题
- sql语句的问题与水晶报表
- C#线程的sleep问题
- datagrid button绑定问题
- dll文件创建问题```急求帮助
- 谁有IM的原码或者方案策划,重金求购
- 再发一帖,关于asp.net 2.0 资源文件使用问题
- 什么时候该进行数据冗余,什么时候不该进行冗余?有规则可循吗?
- 简单抢答题:检测文件是否存在,代码
~0x00000111 = 0xfffffeee,这应该是求反码。前5个是一样的,按位求反运算符是为 int、uint、long 和 ulong 类型预定义的。而且存在 sbyte、byte、short、ushort 到int的隐式转换,所以前5个都是对 int a = 10的求反。
10 = 0x0000000A, ~10 = 0xFFFFFFF5,因为对于负数计算机是采用补码表示(取反+1),11二进制表示为0x0B(.... 0000 1011),取反后(.... 1111 0100),+1 后(.... 1111 0101),正是0xFFFFFFF5uint就更好理解了,因为是无符号,则十进制的值根据二进制递增。long、ulong和int、uint类似。