So a friend is trying to figure out what this is called so we can read more about it.

The concept is/was used by database designers, who needed a compact way to store a list of selected options as a single numerical value, where that number would be unique for any given selection of options.

This was done by assigning an ID value to each option that corresponded with an exponentiation of a base pair, and adding them all together. Since I'm not sure if anything I just said was correct, what I mean is (using base 2 as an example):

Option 1 ID: 1 (2^0)

Option 2 ID: 2 (2^1)

Option 3 ID: 4 (2^2)

So if your selection was both option 1 and 2, the value of that configuration would be 3 (1+2). If your selection was option 1 and 3, it would be 5 (1 + 4).

The presumed property here is that the resulting sum of any given configuration would be unique to that configuration, so that given the value of the sum, one would be able to work backwards to determine which option was selected.

This would be useful to, say, a database guy, who wants a compact way to store a list of selected options as a single value in a row of data.

Can anyone enlighten me on what I would google to learn more about this database storage technique / mathematical principle?

  • $\begingroup$ Bit field, usually. en.wikipedia.org/wiki/Bit_field $\endgroup$ – Thomas Andrews May 12 '15 at 19:03
  • $\begingroup$ Other options: "binary arithmetic", "base conversion". $\endgroup$ – Ken May 12 '15 at 19:05
  • $\begingroup$ But the process is storing logical values, so binary arithmetic is wrong - we never add $a+b$ when $a$ and $b$ are bit fields. And it has nothing to do with base conversion. You never need to represent the number in another base. @Ken $\endgroup$ – Thomas Andrews May 12 '15 at 19:07
  • $\begingroup$ @ThomasAndrews Given the OP said "using base 2 as an example", I thought to add the term "base conversion" for further reading. Maybe they never need a base beyond $2$, or one day they might. As for "binary arithmetic", it's not needed here for storage, but it might come up for manipulation purposes. $\endgroup$ – Ken May 12 '15 at 19:13
  • $\begingroup$ See also 'bitmask' $\endgroup$ – Valentin May 12 '15 at 19:13

This is normally called a "Bit field."

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.