C# BitConverter.ToInt64() 方法
C# 中的 BitConverter.ToInt64() 方法用於返回從位元組陣列中指定位置處八個位元組轉換而來的 64 位有符號整數。
語法
語法如下 −
public static long ToInt64 (byte[] val, int begnIndex);
上面,val 是位元組陣列,而 begnIndex 是 val 中的起始位置。
現在我們來看一個示例 −
示例
using System;
public class Demo {
public static void Main() {
byte[] arr = { 0, 10, 15, 20, 26, 30, 34, 42, 50};
Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr));
for (int i = 0; i < arr.Length - 7; i = i + 8) {
long res = BitConverter.ToInt64(arr, i);
Console.WriteLine("
Value = "+arr[i]);
Console.WriteLine("Result = "+res);
}
}
}輸出
這將產生以下輸出 −
Byte Array = 00-0A-0F-14-1A-1E-22-2A-32 Value = 0 Result = 3036022196155648512
示例
現在我們來看另一個示例 −
using System;
public class Demo {
public static void Main() {
byte[] arr = {0, 0, 0, 10, 20, 0, 0, 25, 30, 0, 0, 0, 35, 45, 55, 65, 75};
Console.WriteLine("Byte Array = {0} ",
BitConverter.ToString(arr));
for (int i = 0; i < arr.Length - 7; i = i + 8) {
long res = BitConverter.ToInt64(arr, i);
Console.WriteLine("
Value = "+arr[i]);
Console.WriteLine("Result = "+res);
}
}
}輸出
這將產生以下輸出 −
Byte Array = 00-00-00-0A-14-00-00-19-1E-00-00-00-23-2D-37-41-4B Value = 0 Result = 1801439937015316480 Value = 30 Result = 4699274364531507230
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP