Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4049764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:59:08+00:00 2026-05-20T13:59:08+00:00

I want to compare 2 byte arrays with masking. So I have data and

  • 0

I want to compare 2 byte arrays with masking. So I have data and dataTemplate:

byte[] data = new byte[] { 0x3b, 0xfe, 0x18, 0x00, 0x00, 0x80, 0x31, 0xfe, 
                           0x45, 0x45, 0x73, 0x74, 0x75, 0x49, 0x44, 0x20, 
                           0x76, 0x65, 0x72, 0x20, 0x31, 0x2e, 0x30, 0xa8 };

byte[] dataTemplate = new byte[] { 0x66, 0xfe, 0x18, 0x00, 0x00, 0x80, 0x31, 0xfe,
                                   0x45, 0x45, 0x73, 0x74, 0x75, 0x49, 0x44, 0x20, 
                                   0x76, 0x65, 0x72, 0x20, 0x31, 0x2e, 0x30, 0xa8 };

And I have mask:

byte[] mask = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                           0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
                           0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };

All bytes what are 0x00 can be chanaged and 0xFF cant. So when I compare data and dataTemplate then lets say data[0] can be 0x3b in one array and something else in the other. But data[9] has to be same in both. Right now I’m doing it like this:

List<byte> maskedDataList = new List<byte>();

for (int i = 0; i < data.Length; i++ )
{
    byte maskedByte = (byte)((dataTemplate[i] & mask[i]));
    atrList.Add(maskedByte);
}

for (int i = 0; i < data.Length; i++)
{
    if ((data[i] & maskedDataList[i]) != MaskedDataList[i])
    {
        throw new Exception("arrays dont match!");
    }
}

But this looks like overkill. Maybe there is better ways doing this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:59:08+00:00Added an answer on May 20, 2026 at 1:59 pm
        for (int i = 0; i < data.Length; i++ )
        {
            if (mask[i] == 0xFF && data[i] != dataTemplate[i]) {
                throw new Exception("arrays dont match!");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two integer array, each size 95700.i want compare to two integer arrays,i
I have a data reader. I want to compare the value in it with
I want to compare varbinary type with byte array. I have tried so far:
I have a simple application in which I want compare two arrays. function check()
I want to compare the first few bytes in byte[] with a string. How
I want to compare two ms-access .mdb files to check that the data they
I want to compare two times in VB.net: I have 1:42:21 PM and I
I want to compare two arrays, one coming from a shoppingcart and the other
I want to compare two xml raw files and capture their differences in data.
I want to create and manipulate large arrays of (4 byte) integers in-memory. By

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.