C#
 Computer >> コンピューター >  >> プログラミング >> C#

C#BitConverter.ToUInt64メソッド


C#のBitConverter.ToUInt64()メソッドは、バイト配列の指定された位置にある8バイトから変換された64ビットの符号なし整数を返すために使用されます。

構文

public static ulong ToUInt64 (byte[] val, int begnIndex);

上記では、valはバイト配列ですが、begnIndexはval内の開始位置です。

using System;
public class Demo {
   public static void Main() {
      byte[] arr = { 0, 0, 1, 3, 5, 7, 9, 11, 15 };
      int count = arr.Length;
      Console.Write("Byte Array... ");
      for (int i = 0; i < count; i++) {
         Console.Write("\n"+arr[i]);
      }
      Console.WriteLine("\n\nByte Array (String representation) = {0} ",
      BitConverter.ToString(arr));
      for (int i = 1; i < arr.Length - 7; i = i + 8) {
         ulong res = BitConverter.ToUInt64(arr, i);
         Console.WriteLine("\nValue = "+arr[i]);
         Console.WriteLine("Result = "+res);
      }
   }
}

出力

Byte Array...
0
0
1
3
5
7
9
11
15
Byte Array (String representation) = 00-00-01-03-05-07-09-0B-0F
Value = 0
Result = 1083970061066240256

using System;
public class Demo {
   public static void Main() {
      byte[] arr = { 0, 0, 1, 3, 5, 7, 9, 11, 15, 0, 1, 6, 8, 10, 20, 25, 36, 34 };
      int count = arr.Length;
      Console.Write("Byte Array... ");
      for (int i = 0; i < count; i++) {
         Console.Write("\n"+arr[i]);
      }
      Console.WriteLine("\n\nByte Array (String representation) = {0} ",BitConverter.ToString(arr));
      for (int i = 1; i < arr.Length - 7; i = i + 8) {
         ulong res = BitConverter.ToUInt64(arr, i);
         Console.WriteLine("\nValue = "+arr[i]);
         Console.WriteLine("Result = "+res);
      }
   }
}

出力

Byte Array...
0
0
1
3
5
7
9
11
15
0
1
6
8
10
20
25
36
34
Byte Array (String representation) = 00-00-01-03-05-07-09-0B-0F-00-01-06-08-0A-14-19-24-22
Value = 0
Result = 1083970061066240256
Value = 0
Result = 2601132293100011776

  1. C#のArray.BinarySearchメソッド

    BinarySearchメソッドを使用して配列要素の場所を取得します。 文字列配列を設定する- string[] str = { "a", "m", "i", "t"}; 次に、Array.BinarySearch-を使用して、文字「t」の位置を取得します。 Array.BinarySearch(str, "t"); これが完全なコードです- 例 using System; using System.Text; public class Demo {    public

  2. C#のClone()メソッド

    C#のClone()メソッドは、配列の同様のコピーを作成するために使用されます。 Clone()メソッドを使用して配列を複製する例を見てみましょう- 例 using System; class Program {    static void Main() {       string[] arr = { "one", "two", "three", "four", "five" };       string[]