日期:2014-05-18  浏览次数:20987 次

如何在byte[] 中查找16进制?
在byte[] 数组中找一个16进制的数如何查找?


------解决方案--------------------
16进制的数
what is it? An integer, a char or a byte?

if it is a byte then:

//byte[] bytes;
byte b = 0x3F;
bool found = Array.IndexOf(bytes, b) >= 0;



if it is an integer then:

C# code

//byte[] bytes;
int n = 0x56789ABC;

bool found = false;
for (int i = 0; i < bytes.Length - 4; i += 4)
{
    if (BitConverter.ToInt32(bytes, i) == n)
    {
        found = true;
        break;
    }
}

------解决方案--------------------
我想在里面找0xFFD8这个十六进制数


short s = 0xFFD8;
for (int i = 0; i < bytes.Length - 2; i += 2)
{
if (BitConverter.ToInt16(bytes, i) == s)
...