本文整理汇总了C#中System.BitConverter.ToUInt64方法的典型用法代码示例。如果您正苦于以下问题:C# BitConverter.ToUInt64方法的具体用法?C# BitConverter.ToUInt64怎么用?C# BitConverter.ToUInt64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.BitConverter
的用法示例。
在下文中一共展示了BitConverter.ToUInt64方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BAToUInt64
// Example of the BitConverter.ToUInt64 method.
using System;
class BytesToUInt64Demo
{
const string formatter = "{0,5}{1,27}{2,24}";
// Convert eight byte array elements to a ulong and display it.
public static void BAToUInt64( byte[ ] bytes, int index )
{
ulong value = BitConverter.ToUInt64( bytes, index );
Console.WriteLine( formatter, index,
BitConverter.ToString( bytes, index, 8 ), value );
}
// Display a byte array, using multiple lines if necessary.
public static void WriteMultiLineByteArray( byte[ ] bytes )
{
const int rowSize = 20;
int iter;
Console.WriteLine( "initial byte array" );
Console.WriteLine( "------------------" );
for( iter = 0; iter < bytes.Length - rowSize; iter += rowSize )
{
Console.Write(
BitConverter.ToString( bytes, iter, rowSize ) );
Console.WriteLine( "-" );
}
Console.WriteLine( BitConverter.ToString( bytes, iter ) );
Console.WriteLine( );
}
public static void Main( )
{
byte[ ] byteArray = {
255, 255, 255, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 100, 167, 179, 182, 224,
13, 0, 202, 154, 59, 0, 0, 0, 0, 170,
170, 170, 170, 170, 170, 0, 0, 232, 137, 4,
35, 199, 138, 255, 255, 255, 255, 255, 255, 255,
255, 127 };
Console.WriteLine(
"This example of the BitConverter.ToUInt64( byte[ ], " +
"int ) \nmethod generates the following output. It " +
"converts elements \nof a byte array to ulong values.\n" );
WriteMultiLineByteArray( byteArray );
Console.WriteLine( formatter, "index", "array elements",
"ulong" );
Console.WriteLine( formatter, "-----", "--------------",
"------" );
// Convert byte array elements to ulong values.
BAToUInt64( byteArray, 3 );
BAToUInt64( byteArray, 0 );
BAToUInt64( byteArray, 21 );
BAToUInt64( byteArray, 7 );
BAToUInt64( byteArray, 29 );
BAToUInt64( byteArray, 13 );
BAToUInt64( byteArray, 35 );
BAToUInt64( byteArray, 44 );
BAToUInt64( byteArray, 43 );
}
}
/*
This example of the BitConverter.ToUInt64( byte[ ], int )
method generates the following output. It converts elements
of a byte array to ulong values.
initial byte array
------------------
FF-FF-FF-00-00-00-00-00-00-00-00-01-00-00-00-64-A7-B3-B6-E0-
0D-00-CA-9A-3B-00-00-00-00-AA-AA-AA-AA-AA-AA-00-00-E8-89-04-
23-C7-8A-FF-FF-FF-FF-FF-FF-FF-FF-7F
index array elements ulong
----- -------------- ------
3 00-00-00-00-00-00-00-00 0
0 FF-FF-FF-00-00-00-00-00 16777215
21 00-CA-9A-3B-00-00-00-00 1000000000
7 00-00-00-00-01-00-00-00 4294967296
29 AA-AA-AA-AA-AA-AA-00-00 187649984473770
13 00-00-64-A7-B3-B6-E0-0D 1000000000000000000
35 00-00-E8-89-04-23-C7-8A 10000000000000000000
44 FF-FF-FF-FF-FF-FF-FF-7F 9223372036854775807
43 FF-FF-FF-FF-FF-FF-FF-FF 18446744073709551615
*/