variables
Can someone explain to me how does variables like that works?
Definition: Code:
#define VOTE_IN_PROGRESS 1check: g_voteStatus & VOTE_IS_RUNOFF add: g_voteStatus |= VOTE_IS_RUNOFF remove: g_voteStatus |= ~VOTE_IS_RUNOFF f.e. If I'll add VOTE_OUTCOME to g_voteStatus it will be 64. It means that previous variables are already inside g_voteStatus? g_voteStatus |= VOTE_IS_OUTCOME and g_voteStatus & VOTE_IS_OVER will return true? |
Re: variables
Research bit values and bit comparisons
|
Re: variables
It means if I'll use bitwise OR to add variable:
64 |= 32 will return 96 then while checking 96 & (16 || 8 || 4 || 2 || 1) will return 0, yes? and 96 & (64 || 32) will not return 0. If I'll use bitwise AND to add: 64 &= 32 it will return 32. It also means that I can add one more variable Code:
#define VOTE_NEW 128 |
Re: variables
You can add the last part without any problem.
64 &= 32 will return 0 If you want to add bits together you have to use bitwise operator |, not ||. |
Re: variables
Quote:
|
Re: variables
Quote:
Code:
1000000 |
Re: variables
Because:
1. I tested it, it returned 0. 2. Bitwise AND compares what the two parts have in common. For example, We have 64(bit 7) and 32(bit 6) If we were to use bitwise AND on these. The result would be as follows: Code:
64 32Code:
64 96Code:
64 96This is also why you check if a variable contains a certain bit with & because it will only return what both sides have in common. |
Re: variables
i see. Thanks for explanation :)
|
| All times are GMT -4. The time now is 15:50. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.