seeker0003 Posted October 27, 2015 Posted October 27, 2015 I'm unsure of what the name for the method I'm looking for is, making it difficult to search for. There is a method of assigning multiple options a number code, and the end user can add together the number codes of their desired choices, and then inputs the result, which is unique for every potential option combination. What I'm wondering is, would someone please tell me what the name of this method is? And maybe how to generate such codes, or a better option. I'm working on a game mod that currently requires text-parsing for option setting, and I need to enable around 12 options in the limited entry space, preferably with greatest user ease. Thanks.
Strange Posted October 27, 2015 Posted October 27, 2015 It sounds like you want to encode the options as bits by making every option a value a power of 2 (A = 1, B = 2, C = 4, etc.) Then when you add the selected options together, it is equivalent to setting the appropriate bits. You can test any option with a boolean AND; for example: (choices & B) > 0 will be true if option B is in the choices. I don't know if this technique has a name or not ...
Sensei Posted October 27, 2015 Posted October 27, 2015 (edited) Bitwise operation https://en.wikipedia.org/wiki/Bitwise_operation To set bit, you should use flags |= 1 << x To clear bit, you should use flags &= ~( 1 << x ); and to test bit you should use if( flags & ( 1 << x ) ) { // bit set } else { // bit clear } where x is bit index from 0...31 for 32 bit integer. << is shift operator. https://en.wikipedia.org/wiki/Arithmetic_shift Edited October 27, 2015 by Sensei
John Cuthber Posted October 28, 2015 Posted October 28, 2015 You can do something similar using primes and multiplying them- but adding n^2 is probably easier.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now