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,447
  • 9
  • 27
  • 45

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
  • 206,299
  • 34
  • 391
  • 426
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,859
  • 2
  • 27
  • 41
1

This is the subset-sum problem.

usr
  • 165,323
  • 34
  • 234
  • 359