Doener

Members
  • Content count

    80
  • Joined

  • Last visited

Community Reputation

134 Neutral

About Doener

  • Rank
    Member
  1. function multiple enum inputes

    The & operator produces a number that has all bits set, that are set in both operands and all other bits unset: 6 (decimal) is 0110 (binary) 1 (decimal) is 0001 (binary) ---------------------------- (we calculate 6 & 1) 0 (decimal) is 0000 (binary) I chose a binary representation using 4 bits. As you can see, none of the bits are set in both operands. Therefore no bits are set in the results.
  2. function multiple enum inputes

    in your function flags is flags2 | flags3 which is 6 (binary 0110) Therefore (in your example): flags & flag1: 6 & 1 = 0 (false) flags & flag2: 6 & 2 = 2 (true) flags & flag3: 6 & 4 = 4 (true) But: flag1: 1 = 1 (true) And that won't change (unless you change flag1). Removing 'flags' from the if-clause doesn't make any sense. Again: & is not logical AND but bitwise AND.
  3. function multiple enum inputes

    hm, not sure if i understood that question. I guess you want to know what value is stored in flags? int flag1 = 1; // binary: 0001 int flag2 = 2; // binary: 0010 int flag3 = 4; // binary: 0100 int flags1 = flag1 | flag2; int flags2 = flag1 | flag3; int flags3 = flag2 | flag3; flags1 will be 3 (binary: 0011) flags2 will be 5 (binary: 0101) flags3 will be 6 (binary: 0110) The actual value doesn't matter that much, you check if a flag is set using bitwise AND.
  4. function multiple enum inputes

    Quote:Original post by Yamian so flags holds multiple intigers? y do u need to say (flags & flag1)? y do they both need to be true? The single & is a bitwise AND. Only the bits that are set in both operands are kept. 12 & 8 = 8 . binary: 1100 & 1000 = 1000 8 & 8 = 8 . binary: 1000 & 1000 = 1000 12 & 4 = 4 . binary: 1100 & 0100 = 0100 8 & 4 = 0 . binary: 1000 & 0100 = 0000 So by choosing values for the flags that have only a single bit set, you can combine them using | (bitwise OR) and find out which ones are set using & (bitwise AND).