The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
What are bitfields?
What are bitfields and how do they work? Esspecially, what does "&" operator do? Thanks.
|
#2
|
||||
|
||||
They are fields that contain a binary number such as 37 (100101), which contains:
32 + 16 8 4 + 2 1 + = 37 They are used for permissions in vB, as well as checkbox profile fields (probably others too). You basically work backwards to see if it contains a value or not. Here: http://ca.php.net/manual/en/language...rs.bitwise.php |
#3
|
||||
|
||||
|
#4
|
|||
|
|||
Quote:
What does it mean - work backwars to see if it contains a value or not. Say, 3 does not contain 1... Then how is it an odd number? Quote:
And what are bit variables? are they arrays? Or varibles that store data in a special form? Or just variables with binary-encoded data? |
#5
|
||||
|
||||
It basically goes through every 2^x where X is less than the # and if it can subtract the X, do so, then proceed - if it is < 0 then skip that subtraction and return false
So say for that function oddeven thing: if the number is 20 (x = 20) 20 - 16 ( >= 0) x & 16 = true 4 - 8 ( < 0) x & 8 = false 4 - 4 ( >= 0) x & 4 = true 0 - 2 ( < 0) x & 2 = false 0 - 1 ( < 0) x & 1 = false |
#6
|
|||
|
|||
I am confused...
"where X is less than the #" - what #? "if it can subtract the X" - what is "it"? Regarding the oddeven thing.. Please show me the process by which 5 & 1 determines that 5 is odd... Thanks. Quote:
|
#7
|
||||
|
||||
37-32 >= 0 so change the number to 5 (which is what is left over)
5 - 16 < 0, so ignore 5 - 8 < 0, so ignore 5 - 4 >= 0, so change the number to 1 (which is what is left over) 1 - 2 < 0, so ignore 1 - 1 >= 0, so change the number to 0 PHP Code:
|
#8
|
||||
|
||||
A Bitfield is a Variable/Database Field where each Bit is being as a On-Off Setting.
This way you can store may settings in one integer. Decimal 5 is Binaray 101 (1*2^0 + 0*2^1 + 1*2^2). & is a binary AND operator, which can be used to check if a Bit is set: 101 & 001 = 001, eg. the Bit is set. |
#9
|
|||
|
|||
Thanks, KirbyDE.
Could someone please explain how does this function work? Quote:
Quote:
2 in zero power multiplied by 1 is 1... 2 in first power multiplied by 0 is 0.... But 2 in second power multiplied by 1 is 5, not 1... (wtf?) |
#10
|
||||
|
||||
Quote:
So if a number is odd, it must have Bit 0 (2^0=1) set, so this functions checks for this Bit being set. Quote:
0*2^1 = 0*2 = 0 1*2^2 = 1*4 = 4 In Total: 5 |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|