码迷,mamicode.com
首页 > 其他好文 > 详细

数据类型互转,字符串编码

时间:2015-11-23 18:48:16      阅读:455      评论:0      收藏:0      [点我收藏+]

标签:

1、字符串转byte数组

string msg="你好你好";

byte[] bytes = System.Text.Encoding.UTF8.GetBytes(msg);

2、byte数组转字符串

byte[] byts = File.ReadAllBytes(@"c:\ooo.txt");
string msg = System.Text.Encoding.UTF8.GetString(byts);

3、字节数组转16进制文本表示

 string msg3= BitConverter.ToString(bytes);//结果:E5-93-88-E5-96-BD-E6-B2-83

4、字节数组转任何的基本类型。比如字节数组转int,single,double等

Single s= BitConverter.ToSingle(bytes, 4);

5、float转字节数组

byte[] bytes1= BitConverter.GetBytes(2.56);

6、16进制转整型

int a=  Convert.ToInt32("AE", 16);

数据类型互转,字符串编码

标签:

原文地址:http://www.cnblogs.com/crhdyl/p/4989142.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!