Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Handling bitmask values

Posted on 2009-05-05
3
2,799 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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