0

I can't remember the name of this, but I remember seeing this once. I need to sum a sequence:

2:hand 
5:leg 
13:head

into one num like 7.

Then when I get 7, I know that it is hand+leg. If I get 20, I know that it is hand+leg+head.

What is the name of this technique?

user1615362
  • 3,657
  • 9
  • 29
  • 46

3 Answers3

3

Do you mean a Flags enumeration?

[Flags]
enum Parts
{
    Hand = 1,
    Leg = 2,
    Head = 4,
}

Example:

Parts p = Parts.Hand | Parts.Leg;

bool isHand = (p & Parts.Hand) != 0;
dtb
  • 213,145
  • 36
  • 401
  • 431
2

You are talking about a bit mask and is typically implemented using an enum decorated with the [FlagsAttribute]. The values would be powers of two.

See the following SO answer for an explanation of using the [FlagsAttribute] in C#.

https://stackoverflow.com/a/3261485/444610

Community
  • 1
  • 1
Seth Flowers
  • 8,990
  • 2
  • 29
  • 42
1

This is the subset-sum problem.

usr
  • 168,620
  • 35
  • 240
  • 369