In some code I'm working on, I have to take care of ten independent parameters that can take one of two values ββ(0 or 1). This creates 2 ^ 10 different conditions. Some of the conditions are never met and can be omitted, but those that do occur are still LOTS and make switchall cases insane.
I want to use 10 operators ifinstead of huge switch. For this, I know that I have to use flag bits, or rather flags, since the language is javascript and it is easier to work with a 10-byte string with a representation of a 10-bit binary.
Now, my problem is that I do not know how to implement this. I saw that it was used in APIwhere multiple-choice variants are displayed with numbers 1, 2, 4, 8, ..., n ^ (n-1), which are the decimal equivalents of 1, 10, 100, 1000, and t .d. in binary format. Therefore, if we make a type call bar = foo(7), bar will be an object with any parameters that are allowed by the three right-most flags.
I can convert the decimal to binary and to each operator check ifto see if the corresponding digit is set. But I am wondering if there is a way to determine the n-thdecimal digit number, zero or one in binary form, without actually performing the conversion?
source
share