?
Solved

Handling bitmask values

Posted on 2009-05-05
3
Medium Priority
?
2,810 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
[X]
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
  • 2
3 Comments
 
LVL 8

Assisted Solution

by:Haris V
Haris V earned 600 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

718 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