search in bit array in c#

user2922938

if there are two array, first array size 100 bit and second array size 32 bit,i want to search 32 bit array in first array 100 bit

BitArray bits = new BitArray(100);  
BitArray bitss = new BitArray(32); 


bitss.Set(16,true);
bitss.Set(25,true);
bitss.Set(26,true);
bitss.Set(28,true);
bitss.Set(29,true);
bitss.Set(31,true);

for (int i = 0; i < (bits.Length)-1;i++ )

if ((bits[i] == bitss[0] &&
    bits[i + 1] == bitss[1] &&
    bits[i + 2] == bitss[2] &&
    bits[i + 3] == bitss[3] &&
    ...
    bits[i + 31] == bitss[31]))

    Console.WriteLine("Found");

is there better method for search bitss array in bit array without use ( if and == ) in C#

AlliterativeAlice

It can definitely be shortened with another for loop:

for (int i = 0; i < (bits.Length)-1;i++ ) {
    bool found = true;
    for (int j = 0; j < 32; j++) {
        if (bits[i + j] != bits[j]) {
            found = false;
            break;
        }
    }
    if (found) Console.WriteLine("Found");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

storing a bit in a bit of character array in C linux

From Dev

Array of Bit_fields in C

From Dev

Bit Manipulation on char array in c

From Dev

Global Array in 16 bit C

From Dev

Bit Manipulation on char array in c

From Dev

Merge bit variables in array in C

From Dev

bool array vs bit array in C

From Dev

C, Creating a 32 bit pointer to a 8 bit array

From Dev

convert 128 bit to array of 8 bit c#

From Dev

remainder of bit array division C++

From Dev

Converting array to 8-bit codes in c

From Dev

A bit of recursion, array of characters and strcpy in C

From Dev

How to pass element of bit array into function in C

From Dev

Search array of a class c#

From Dev

C/C++ Converting a 64 bit integer to char array

From Dev

Recursive unsorted array search algorithm in C?

From Dev

2D array search in C

From Dev

Binary search of strings in an array in C#

From Dev

C++ binary search with char array

From Dev

Binary search of strings in an array in C#

From Dev

C++ Binary Search - Array Position Variables

From Dev

Unordered Array Linear Search c++

From Dev

Bitwise operation in C, referring to a position in an 8bit array

From Dev

Extract 14-bit values from an array of bytes in C

From Dev

Inserting an array of 16-bit ints to MySQL, from C

From Dev

Store 3 bit binary numbers in C++ array

From Dev

Bit manipulation; Converting a 16-bit value into an array of 16 Boolean values? C language

From Dev

When targeting 64-bit platforms in C, is it better to use 64-bit variables for array references?

From Dev

adjancecy list, split an array and search a word in this array in c