Hello,

I'm searching for a logical syntax or method for handling following problem.

I have 3 values in bitmask format:
1 = A
2 = B
4 = C

Possible values are: 1, 2, 3, 4, 5, 6 and 7.

Now I want a kind of for-each-loop to insert the values A, B and/or C in the database.

Example 1:
Incoming value = 1
Single insert into database: A

Example 2:
Incoming value = 7
Three inserts into database: A, B and C.

What is the fastest way to do this in C# .net?

###### Who is Participating?

Author Commented:
I've found it:

double intGetal;
double inti;
int intJ;
double[] intGetallen = new double[3];
double intWaarde;

intGetal = 7;

intJ = 0;

for (inti = 2; inti >= 0; inti = inti - 1)
{

intWaarde = intGetal - Math.Pow(2, inti);
if (intWaarde >= 0)
{
intGetal = intGetal - Math.Pow(2, inti);
intGetallen[intJ] = Math.Pow(2, inti);
intJ = intJ + 1;
}
}

Console.WriteLine(intGetallen[0] + " - " + intGetallen[1] + " - " + intGetallen[2]);
0

Commented:
0

Author Commented:
It's usefull, but I'm searching for a C# .net equivalent. I hope anybody can help me :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.