Solved

Handling bitmask values

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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