如何将汉字转换为汉字的ascii码范围是c#互转

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
技术备份,欢迎大家交流。
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
& & & & {& & & & & & byte[] buff = new byte[Msg.Length / 2];& & & & & & string Message = "";& & & & & & for (int i = 0; i & buff.L i++)& & & & & & {& & & & & & & & buff[i] = byte.Parse(Msg.Substring(i * 2, 2),& & & & & & & & & &System.Globalization.NumberStyles.HexNumber);& & & & & & }& & & & & & System.Text.Encoding chs = System.Text.Encoding.ASCII;& & & & & & Message = chs.GetString(buff);& & & & & & return M& & & & }& & & & public static string HexToStr(string Msg)& & & & {& & & & & & byte[] buff = new byte[Msg.Length / 2];& & & & & & string Message = "";& & & & & & for (int i = 0; i & buff.L i++)& & & & & & {& & & & & & & & buff[i] = byte.Parse(Msg.Substring(i * 2, 2),& & & & & & & & & &System.Globalization.NumberStyles.HexNumber);& & & & & & }& & & & & & System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");& & & & & & Message = chs.GetString(buff);& & & & & & return M& & & & }& & & & public static string StrToHex(string Msg)& & & & {& & & & & & byte[] bytes = System.Text.Encoding.Default.GetBytes(Msg);& & & & & & string str = "";& & & & & & for (int i = 0; i & bytes.L i++)& & & & & & {& & & & & & & & str += string.Format("{0:X}", bytes[i]);& & & & & & }& & & & & && & & & }string s1 = StrToHex("我家住在黄土高坡");string s2 = HexToStr(s1);string s3 =&HexToASCII(“373839”);
阅读(3062)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'C# 十六进制转中文、转ASCII',
blogAbstract:'& & & & public static string HexToASCII(string Msg)& & & & {& & & & & & byte[] buff = new byte[Msg.Length / 2];& & & & & & string Message = \"\";& & & & & & for (int i = 0; i & buff.L i++)& & & & & & {& & & & & & & & buff[i] = byte.Parse(Msg.Substring(i * 2, 2),& & & & & & & &',
blogTag:'c#,ascii,gb2312',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:6,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'技术备份,欢迎大家交流。',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}2010年 总版技术专家分年内排行榜第一2009年 总版技术专家分年内排行榜第一
2011年 总版技术专家分年内排行榜第二
2012年8月 C/C++大版内专家分月排行榜第三2012年7月 C/C++大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。C#16进制ASCII码与对应的字符的互转
C#16进制ASCII码与对应的字符的互转
//ASCII码转成对应的字符串
string s = "3133";
byte[] buff = new byte[s.Length / 2];
int index = 0;
for (int i = 0; i & s.L i += 2)
buff[index] = Convert.ToByte(s.Substring(i, 2), 16);
string result = Encoding.Default.GetString(buff);
MessageBox.Show(result);
运行结果:A1022013
//字符串转成对应的ASCII码
string s2 = "A1022013";
byte [] ba = System.Text.ASCIIEncoding.Default.GetBytes(s2) ;
StringBuilder sb = new StringBuilder();
foreach (byte b in ba)
sb.Append(b.ToString("x"));
MessageBox.Show(sb.ToString());
运行结果:3133
发表评论:
TA的最新馆藏温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(16707)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'C#汉字Unicode编码相互转换',
blogAbstract:'Unicode和汉字编码小知识  将汉字进行UNICODE编码,如:“王”编码后就成了“\\王”,UNICODE字符以\\u开始,后面有4个数字或者字母,所有字符都是16进制的数字,每两位表示的256以内的一个数字。而一个汉字是由两个字符组成,于是就很容易理解了,“738b”是两个字符,分别是“73”“8b”。但是在将 UNICODE字符编码的内容转换为汉字的时候,',
blogTag:'汉字转unicode编码,unicode编码转汉字',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:1,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:2,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}博客访问: 161495
博文数量: 50
博客积分: 2000
博客等级: 大尉
技术积分: 394
注册时间:
APP发帖 享双倍积分
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
public static string Str2Hex(string s) &&&&&&& { &&&&&&&&&&& string result = string.E &&&&&&&&&&&& byte[] arrByte = System.Text.Encoding.GetEncoding("GB2312").GetBytes(s);&&&& &&&&&&&&&&& for(int i = 0; i < arrByte.L i++) &&&&&&&&&&& { &&&&&&&&&&&&&&& result += "&#x" + System.Convert.ToString(arrByte[i], 16) + ";";&&&&&&& //Convert.ToString(byte, 16)把byte转化成十六进制string &&&&&&&&&&& } &&&&&&&&&&&& &&&&&&& } 变成可以在网上传输的那种16进制编码,类似%8D%E2这种?这样的话,用System.Web.HTTPUtility.URLEncode()就行。&&&& 光光10进制转换到16进制的话,可以用 & bytes(i).ToString("X"),&& 这是将一个字节转换为一个16进制字符串,"X"表示大写16进制字符,用"x"可以得到小写的。&& 参考字符串(含有汉字)转化为ascII16进制问题
&&&&&&&&public&string&EncodingSMS(string&s)&&&&&&&&&{&&&&&&&&&&&&&string&result&=&string.E&&&&&&&&&&&&&&byte[]&arrByte&=&System.Text.Encoding.GetEncoding("GB2312").GetBytes(s);&&&&&&&&&&&&&&&&&for(int&i&=&<SPAN style="COLOR: #;&i&<&arrByte.L&i++)&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&result&+=&System.Convert.ToString(arrByte[i],&<SPAN style="COLOR: #);&&&&&&&&//Convert.ToString(byte,&16)把byte转化成十六进制string&&&&&&&&&&&&&}&&&&&&&&&&&&&&return&&&&&&&&&&}
&&&&&&&&public&string&DecodingSMS(string&s)&&&&&&&&&{&&&&&&&&&&&&&string&result&=&string.E&&&&&&&&&&&&&&byte[]&arrByte&=&new&byte[s.Length / 2];&&&&&&&&&&&&&int&index&=&<SPAN style="COLOR: #;&&&&&&&&&&&&&for(int&i&=&<SPAN style="COLOR: #;&i&<&s.L&i&+=&<SPAN style="COLOR: #)&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&arrByte[index++]&=&Convert.ToByte(s.Substring(i,<SPAN style="COLOR: #),<SPAN style="COLOR: #);&&&&&&&&//Convert.ToByte(string,16)把十六进制string转化成byte&&&&&&&&&&&&&}&&&&&&&&&&&&&result&=&System.Text.Encoding.Default.GetString(arrByte);&&&&&&&&&&&&&&return&&&&&&&&&&&}
加码解码的规则如下: 加码时将字符串中的所有字符转换成其对应的ASCII值的16进制值,例如:“A”的ASCII码值为65,以16进制值表示为41,故应发送两个字符“41”以代表字符“A”。 对于汉字则以其内码的16进制值来表示,如“测试”应为:B2E2CAD4。 原理: &
&&&&&&&&&&&&string&aaa&=&"AB测试"; &&&&&&&&&&&&byte[]&bbb&=&System.Text.Encoding.Default.GetBytes(aaa); &&&&&&&&&&&&string&ccc&&=&System.Text.Encoding.Default.GetString(bbb);
&&&&&&&&&&&&for(int&i&=&<SPAN style="COLOR: #;&i&<&bbb.L&i++)&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&Response.Write(System.Convert.ToString(bbb[i],&<SPAN style="COLOR: #));&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&& &&&&&&&&&&&&Response.Write(ccc);
阅读(10863) | 评论(0) | 转发(1) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。}

我要回帖

更多关于 汉字转ascii码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信