字符如何以整型输出

webphoenix 2010-11-18 04:09:51
在C语言中
下面这个将输出 -32
char a = 0xe0;
printf("%d",a);
//==>输出 -32

如何在C#中实现

char a = (char)0xe0;
Response.Write(string.format("{0}",a));//这里该怎么写,才能输出 -32 ?
...全文
230 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
webphoenix 2010-11-18
  • 打赏
  • 举报
回复
gomoku 正解,问题解决,谢谢各位!
zxj2634 2010-11-18
  • 打赏
  • 举报
回复
Response.Write(string.format("{0}",(int)a));

或者

convert.toInt(a)
蝶恋花雨 2010-11-18
  • 打赏
  • 举报
回复
gomoku 的结果是-32 format f大写
q107770540 2010-11-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 gomoku 的回复:]

C# code

sbyte b = unchecked( (sbyte)0xe0 );
Response.Write(string.format("{0}",b));


C#里char的取值范围为0-65535。
[/Quote]
兔子-顾问 2010-11-18
  • 打赏
  • 举报
回复
SByte,一直没用过。记住了。Sign Byte的意思,对吧。
兔子-顾问 2010-11-18
  • 打赏
  • 举报
回复
gomoku v5
编程爱好者L 2010-11-18
  • 打赏
  • 举报
回复
这样可以实现:
int a=10;
int b=0-a;
gomoku 2010-11-18
  • 打赏
  • 举报
回复

sbyte b = unchecked( (sbyte)0xe0 );
Response.Write(string.format("{0}",b));

C#里char的取值范围为0-65535。
兔子-顾问 2010-11-18
  • 打赏
  • 举报
回复
实现不了,c#下不支持一个字节有符号的变量类型。
编程爱好者L 2010-11-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]

Convert.ToInt32(0xe0) //224
[/Quote]
up
烈火蜓蜻 2010-11-18
  • 打赏
  • 举报
回复
Response.Write(string.format("{0}",(int)a));
q107770540 2010-11-18
  • 打赏
  • 举报
回复
Convert.ToInt32(0xe0) //224

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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