Jump to content

How do you make unique option codes for input as a parameter?

Featured Replies

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.

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 ...

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 by Sensei

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.