惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
腾讯CDC
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
博客园_首页
D
DataBreaches.Net
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
月光博客
月光博客
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
Vercel News
Vercel News
WordPress大学
WordPress大学
J
Java Code Geeks
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42

博客园 - 宝气狗

【摄影】2008年06月07日西塘 【摄影】2008年05月24日大明山 2007年11月——感受黄山,天下无山。 托管/非托管类型对照 【数据库】遍历XML根下的一级节点 - 宝气狗 - 博客园 Enterprise Library中缓存过期策略探究 css中的nowrap 2007年9月15日 九溪-五云山-梅家坞之行 宝气狗的新闻博开始使用http://webbased.cn [设计模式] 15.Command 命令模式 [设计模式] 22.State 状态模式 [设计模式] 23.Strategy 策略模式 值类型装箱拆箱需要注意的地方 CLR如何控制类型中字段的布局 MSIL指令速查 内存一致性问题(续一) 内存一致性问题 如何循序渐进向DotNet架构师发展 关于将Queue中的数据拼接成xml的经验
将基础数据类型与字节数组相互转换
宝气狗 · 2007-10-28 · via 博客园 - 宝气狗

BitConverter 类

将基础数据类型与字节数组相互转换。

命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)

此类便于操作基本形式的类型。一个字节定义为一个 8 位无符号整数。

举例:返回由字节数组的元素转换来的 String。

// Example of the BitConverter.ToString( byte[ ] ) method.
using System;
class BytesToStringDemo
{
// Display a byte array with a name.
public static void WriteByteArray( byte[ ] bytes, string name )
{
const string underLine = "--------------------------------";
Console.WriteLine( name );
Console.WriteLine( underLine.Substring( 0,
Math.Min( name.Length, underLine.Length ) ) );
Console.WriteLine( BitConverter.ToString( bytes ) );
Console.WriteLine( );
}
public static void Main( )
{
byte[ ] arrayOne = {
0,   1,   2,   4,   8,  16,  32,  64, 128, 255 };
byte[ ] arrayTwo = {
32,   0,   0,  42,   0,  65,   0, 125,   0, 197,
0, 168,   3,  41,   4, 172,  32 };
byte[ ] arrayThree = {
15,   0,   0, 128,  16,  39, 240, 216, 241, 255,
127 };
byte[ ] arrayFour = {
15,   0,   0,   0,   0,  16,   0, 255,   3,   0,
0, 202, 154,  59, 255, 255, 255, 255, 127 };
Console.WriteLine( "This example of the " +
"BitConverter.ToString( byte[ ] ) \n" +
"method generates the following output.\n" );
WriteByteArray( arrayOne, "arrayOne" );
WriteByteArray( arrayTwo, "arrayTwo" );
WriteByteArray( arrayThree, "arrayThree" );
WriteByteArray( arrayFour, "arrayFour" );
}
}
/*
This example of the BitConverter.ToString( byte[ ] )
method generates the following output.
arrayOne
--------
00-01-02-04-08-10-20-40-80-FF
arrayTwo
--------
20-00-00-2A-00-41-00-7D-00-C5-00-A8-03-29-04-AC-20
arrayThree
----------
0F-00-00-80-10-27-F0-D8-F1-FF-7F
arrayFour
---------
0F-00-00-00-00-10-00-FF-03-00-00-CA-9A-3B-FF-FF-FF-FF-7F
*/
参见Webbased.cn相关文章