Solved

Handling bitmask values

Posted on 2009-05-05
3
2,792 Views
Last Modified: 2013-12-17
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?

Thanks in advance.
0
Comment
Question by:corcon
  • 2
3 Comments
 
LVL 8

Assisted Solution

by:Haris V
Haris V earned 150 total points
Comment Utility
0
 

Author Comment

by:corcon
Comment Utility
It's usefull, but I'm searching for a C# .net equivalent. I hope anybody can help me :-)
0
 

Accepted Solution

by:
corcon earned 0 total points
Comment Utility
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]);
                Console.ReadLine();
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now