473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to compare two byte arrays?

Ole
How do I compare two byte arrays in a if statement?

Thanks
Ole
Jun 23 '06 #1
2 4798
Hello, Ole!

O> How do I compare two byte arrays in a if statement?

You have to loop through array comparing every item.

Smth like

bool IsEqual(byte[] arr1, byte[] arr2)
{
if ( arr1 == null || arr2 == null )
return false;

if ( arr1.Length != arr2.Length )
return false;

//and here is the check loop
for(int i = 0; i < arr1.Length; i++ )
{
if ( arr1[i] != arr2[i] )
return false;
}
return true;
}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Jun 23 '06 #2
Ole
Hello Vadym,

Thanks alot!

Regards
Ole

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:e5**************@TK2MSFTNGP04.phx.gbl...
Hello, Ole!

O> How do I compare two byte arrays in a if statement?

You have to loop through array comparing every item.

Smth like

bool IsEqual(byte[] arr1, byte[] arr2)
{
if ( arr1 == null || arr2 == null )
return false;

if ( arr1.Length != arr2.Length )
return false;

//and here is the check loop
for(int i = 0; i < arr1.Length; i++ )
{
if ( arr1[i] != arr2[i] )
return false;
}
return true;
}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Jun 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
5
by: Jim H | last post by:
I will have many 3 byte Byte arrays. Is there a way to compare the values without iterating through and comparing each element in the code? Example: byte lTest1 = new byte {0x1, 0x2, 0x3};...
3
by: NathanV | last post by:
I'm trying to compare two byte's. I think I have to use binary operators. How can I tell if two bytes have the same value? Also, I have a function that is returning a byte value. Is there a...
2
by: nobs | last post by:
Hi I have two byte arrays (each with a length of 8 bytes) an I'd like to compare them if they are equal. The operator == shouldn't work because its not a basic Data Type so I used the method...
1
by: Jacob Thastrup | last post by:
Hi is there an easy way to compare arrays without going through each entry in the arrays? Say I have two arrays and I want to find entries that are not present in both. Thanks Jacob Thastrup
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
2
by: Tom | last post by:
What's the best way to compare two byte arrays? Right now I am converting them to base64 strings and comparing those, as so: 'result1 and result2 are two existing byte arrays that have been...
8
by: Turbot | last post by:
Hello, Anyone know how to compare two byte arrays without going through each item in the array. I actually want to compare two bitmap objects to see if they both contain the same picture bit...
5
by: Oleg Subachev | last post by:
Is there other way of comparing two byte arrays than iterating through the two and compare individual bytes ? Oleg Subachev
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.