c#用memcmp比较字节数组
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
【c#用memcmp比较字节数组】///
/// 用memcmp比较字节数组
///
/// 字节数组1
/// 字节数组2
///
public static int MemoryCompare(byte[] b1, byte[] b2)
{
IntPtr retval = memcmp(b1, b2, new IntPtr(b1.Length));
return retval.ToInt32();
}
///
/// 比较字节数组
///
/// 字节数组1
/// 字节数组2
///
public static int MemoryCompare2(byte[] b1, byte[] b2)
{
int result = 0;
if (b1.Length != b2.Length)
result = b1.Length - b2.Length;
else
{
for (int i = 0;
i < b1.Length;
i++)
{
if (b1[i] != b2[i])
{
result = (int)(b1[i] - b2[i]);
break;
}
}
}
return result;
}
///
/// memcmp API
///
/// 字节数组1
/// 字节数组2
///
[DllImport("msvcrt.dll")]
private static extern IntPtr memcmp(byte[] b1, byte[] b2, IntPtr count);
}
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- JS中的各种宽高度定义及其应用
- 由浅入深理解AOP
- 【译】20个更有效地使用谷歌搜索的技巧
- 涉毒患者(新诗)
- 参保人员因患病来不及到指定的医疗机构就医,能否报销医疗费用()
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- 汇讲-勇于突破