Is there a name for the technique of using base-2 numbers to encode a list of unique options?
Posted
by Lunatik
on Stack Overflow
See other posts from Stack Overflow
or by Lunatik
Published on 2010-06-01T15:17:17Z
Indexed on
2010/06/01
15:23 UTC
Read the original article
Hit count: 265
Apologies for the rather vague nature of this question, I've never been taught programming and Google is rather useless to a self-help guy like me in this case as the key words are pretty ambiguous.
I am writing a couple of functions that encode and decode a list of options into a Long so they can easily be passed around the application, you know this kind of thing:
1 - Apple
2 - Orange
4 - Banana
8 - Plum
etc.In this case the number 11 would represent Apple, Orange & Plum.
I've got it working but I see this used all the time so assume there is a common name for the technique, and no doubt all sorts of best practice and clever algorithms that are at the moment just out of my reach.
© Stack Overflow or respective owner