Solved

Handling bitmask values

Posted on 2009-05-05
3
2,795 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
ID: 24302972
0
 

Author Comment

by:corcon
ID: 24303044
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
ID: 24303886
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
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 …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

21 Experts available now in Live!

Get 1:1 Help Now