You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EC.Utils.Helper
{
public class ByteHelper
{
public static string IntToHex(int i)
{
return Convert.ToString(i, 16);
}
/// <summary>
/// int 类型转回为 byte[]
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static byte[] IntToByte2(int i)
{
byte[] a = new byte[2];
a[0] = (byte)(i >> 8);
a[1] = (byte)i;
return a;
}
/// <summary>
/// 截取byte 数组
/// </summary>
/// <param name="frombyte"></param>
/// <param name="begIndex"></param>
/// <param name="lenth"></param>
/// <returns></returns>
public static byte[] SubArr(byte[] frombyte, int begIndex, int lenth)
{
byte[] subByte = new byte[lenth];
int icount = (begIndex + lenth);
for (int x = begIndex; x< icount; x++) {
subByte[x - begIndex] = frombyte[x];
}
return subByte;
}
}
}