比较字节数组 [英] Comparing byte arrays

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

问题描述




如何在VB.NET中比较两个字节数组


感谢

Peter

Hi

how can I compare two byte arrays in VB.NET

Thank
Peter

推荐答案

Hi-

这是一个很酷的方法,用其中一个哈希值来做这个>
MVP。 (Corrado Cavalli)
http://groups.google.com/gr*********...TNGP12.phx.gbl

(注意换行。)

Joe

" Peter" <一个******* @ discussions.microsoft.com>在留言中写道

news:18 ********************************** @ microsof t.com ...
Hi-
Here''s a cool way to do it with a hash value by one of the
MVPs. (Corrado Cavalli)
http://groups.google.com/gr*********...TNGP12.phx.gbl
(Watch for line wrapping.)
Joe
"Peter" <an*******@discussions.microsoft.com> wrote in message
news:18**********************************@microsof t.com...


如何在VB.NET中比较两个字节数组?

谢谢
Peter
Hi,

how can I compare two byte arrays in VB.NET?

Thanks
Peter



Hi-

这是一个很酷的方式来做一个哈希值的其中一个

MVP。 (Corrado Cavalli)
http://groups.google.com/gr*********...TNGP12.phx.gbl

(注意换行。)

Joe

" Peter" <一个******* @ discussions.microsoft.com>在留言中写道

news:18 ********************************** @ microsof t.com ...
Hi-
Here''s a cool way to do it with a hash value by one of the
MVPs. (Corrado Cavalli)
http://groups.google.com/gr*********...TNGP12.phx.gbl
(Watch for line wrapping.)
Joe
"Peter" <an*******@discussions.microsoft.com> wrote in message
news:18**********************************@microsof t.com...


如何在VB.NET中比较两个字节数组?

谢谢
Peter
Hi,

how can I compare two byte arrays in VB.NET?

Thanks
Peter



嗨彼得,


在Joe发送给你的那个是来自David,Herfried,Spam的样本并且

Corrado,虽然Joe确实说Corrado的那个很酷但我认为那个来自Herfried的人可能会更快。因为当它是一个非常大的bytearray或当第一个字节是直接不同时,可以在进程上停止



(当bytearrays不相同时)。我自己也做了一个

一个。

使用内存流序列化bytearray。 (我的一个问题是

它使用了2倍的内存,因此对于20Mb和

以上的数组不太好用。)


我很好奇什么是最快的(当字节区域长度不等

而不是来自Herfried和我的那些当然都是最快的但是

是从Corrado添加程序)


Cor。


\\\

Dim abyt1()As Byte = {12,55,88,32}

Dim abyt2()As Byte = {12,55,87,32}

如果是abyt1。长度= abyt2.Length然后

Dim mem1 As New IO.MemoryStream

Dim mem2 As New IO.MemoryStream

Dim binWriter1 As New IO。 BinaryWriter(mem1)

Dim binWriter2 As New IO.BinaryWriter(mem2)

binWriter1.Write(abyt1)

binWriter2.Write(abyt2)

Dim binReader1 As New IO.BinaryReader(binWriter1.BaseStream)

Dim binReader2 As New IO.BinaryReader(binWriter2.BaseStream)

binReade r1.BaseStream.Position = 0

binReader2.BaseStream.Position = 0

Dim a,b As String

a = binReader1.ReadChars(abyt1 .Length)

b = binReader2.ReadChars(abyt2.Length)

如果<> b然后

MessageBox.Show(not equal char)

结束如果

Else

MessageBox。显示(不等长)

结束如果

///
Hi Peter,

In the one Joe was sending you is a sample from David, Herfried, Spam and
Corrado, although Joe did say the one from Corrado was cool I thought that
the one from Herfried could be faster. Because that can stop on the process
when it is a very large bytearray or when the first byte is direct different
(what is likely when bytearrays are not the same). I made one myself too
one.
Is serializes the bytearray using the memorystream. (A problem with mine is
that it uses 2 times the memory so not good usable with arrays from 20Mb and
more).

I am curious what is the fastest (when the bytes areas length are unequal
than the ones from Herfried and me are of course both the fastest but that
is to add in the procedure from Corrado too)

Cor.

\\\
Dim abyt1() As Byte = {12, 55, 88, 32}
Dim abyt2() As Byte = {12, 55, 87, 32}
If abyt1.Length = abyt2.Length Then
Dim mem1 As New IO.MemoryStream
Dim mem2 As New IO.MemoryStream
Dim binWriter1 As New IO.BinaryWriter(mem1)
Dim binWriter2 As New IO.BinaryWriter(mem2)
binWriter1.Write(abyt1)
binWriter2.Write(abyt2)
Dim binReader1 As New IO.BinaryReader(binWriter1.BaseStream)
Dim binReader2 As New IO.BinaryReader(binWriter2.BaseStream)
binReader1.BaseStream.Position = 0
binReader2.BaseStream.Position = 0
Dim a, b As String
a = binReader1.ReadChars(abyt1.Length)
b = binReader2.ReadChars(abyt2.Length)
If a <> b Then
MessageBox.Show("not equal char")
End If
Else
MessageBox.Show("not equal length")
End If
///


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

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