C#中的BitConverter.ToInt32()方法
C#中的BitConverter.ToInt32()方法用于返回从字节数组中指定位置的四个字节转换而来的32位带符号整数。
语法
语法如下-
public static int ToInt32 (byte[] val, int begnIndex);
在上面,val是字节数组,而begnIndex是val中的开始位置。
示例
现在让我们看一个例子-
using System;
public class Demo {
public static void Main(){
byte[] arr = { 10, 20, 30, 40, 50};
Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr));
for (int i = 1; i < arr.Length - 3; i = i + 4) {
int res = BitConverter.ToInt32(arr, i);
Console.WriteLine("\nValue = "+arr[i]);
Console.WriteLine("Result = "+res);
}
}
}输出结果
这将产生以下输出-
Byte Array = 0A-14-1E-28-32 Value = 20 Result = 841489940
示例
现在让我们来看另一个示例-
using System;
public class Demo {
public static void Main(){
byte[] arr = { 0, 0, 10, 15, 20, 26, 32, 34, 40};
Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr));
for (int i = 1; i < arr.Length - 3; i = i + 4) {
int res = BitConverter.ToInt32(arr, i);
Console.WriteLine("\nValue = "+arr[i]);
Console.WriteLine("Result = "+res);
}
}
}输出结果
这将产生以下输出-
Byte Array = 00-00-0A-0F-14-1A-20-22-28 Value = 0 Result = 336529920 Value = 26 Result = 673325082
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练