PeterH wrote:ksarnelli wrote:Now tell me what value 11 would mean?
Seems this is the point?
11 is binary 1011 (8+2+1), so it means options 1, 2 and 4 (right to left) are set.
You number the right-most bit "1". As it's the 1st from right.
You
might also number it "0". As it's value is 2**0.
11 in my example is decimal as that is what gets passed as an argument to the method (sorry, I chose a poor example that looked binary). You can't expect a person to pass binary to a method - especially when you start getting into methods with a bitfield that contains hundreds of options - the proper way to do this is to add up the decimal values of all options and have them deconstructed at runtime. Just see any method in the Windows API if you want to see what I am talking about.
Anyway, I think the best way to resolve this is to not use combo bitfields for any argument that requires a default value. Those should be separate arguments. Maybe the hash() method should look like this (making use of some new constants):
hash ( enum algo, string str, enum mode, bitfield options )
enum algo:
HASH_MD5 = 0 (default)
HASH_SHA1 = 1
HASH_SHA256 = 2
HASH_SHA512 = 3
HASH_CRC32 = 4
enum mode:
HASH_STRING = 0 (default)
HASH_FILE = 1
bitfield options:
HASH_SHOWPROGRESS = 1 (Only valid when mode = HASH_FILE)
HASH_FUTUREOPTION1 = 2
HASH_FUTUREOPTION2 = 4
HASH_FUTUREOPTION3 = 8
etc
And then a future call could look something like this:
hash(HASH_SHA256, "c:\test.txt", HASH_FILE, HASH_SHOWPROGRESS + HASH_FUTUREOPTION2)
which would be equivalent to:
hash(2, "c:\test.txt", 1, 5)
and could easily by parsed at runtime back to derive what exactly the user selected.