比较字节数组的最佳方法是什么 [英] What is the best way to compare byte array

查看:65
本文介绍了比较字节数组的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

byte[] array1 = new byte[]{0x1b,0x00,0x08,0x23}

byte[] array2 = new byte[]{0xFF,0xFF,0xFF,0xFF}

byte[] array3 = new byte[]{0x1a,0x06,0x04,0x25}




在这里,我如何检查array3 [0]是否大于或等于array1 [0]并小于和等于array2 [0]
就像遍历array3中的每个项目一样


请帮助我找到检查我的array3是否在array1和array2之间的最佳方法.




Here how can i check whether array3[0] is greater than or equal to array1[0] and lesser than and equal to array2[0]
like that iterating through each item in the array3


Please help me to find the best way to check whether my array3 is in the range between array1 and array2

推荐答案

没有最好的方法",但是,有很多有意义的方法.
例如,您可以比较数组中所有项目的总和,或者计数不等式array1[i] <= array3[i] <= array2[i]保持多少次.
There isn''t a ''best way'', however, there are meaningful ways.
You may, for instance compare the sums of alle the items of the arrays or, alternatively count how many times the inequality array1[i] <= array3[i] <= array2[i] holds.


简单的方法是:

The simple way is:

byte[] array1 = new byte[] { 0x1b, 0x00, 0x08, 0x23 };
byte[] array2 = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
byte[] array3 = new byte[] { 0x1a, 0x06, 0x04, 0x25 };
if (array1.Length == array2.Length && array2.Length == array3.Length)
    {
    for (int i = 0; i < array1.Length; i++)
        {
        if (array3[i] > array2[i] || array3[i] < array1[i])
            {
            // fail!
            break;
            }
        }
    }


这篇关于比较字节数组的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆