Raised This Month: $ Target: $400
 0% 

variables


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-15-2013 , 17:03   Re: variables
Reply With Quote #7

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	32
1	0	0	=0
2	0	0	=0
4	0	0	=0
8	0	0	=0

16	0	0	=0
32	0	1	=0
64	1	0	=0
128	0	0	=0
			=0
If on the other hand they would have something in common. Like 64(bit 7) and 96(bit 6 and 7) the result would be as follows:
Code:
	64	96
1	0	0	=0
2	0	0	=0
4	0	0	=0
8	0	0	=0

16	0	0	=0
32	0	1	=0
64	1	1	=64
128	0	0	=0
			=64
Compare this to the bitwise OR which basically adds up all the 1's into one result.
Code:
	64	96
1	0	0	=0
2	0	0	=0
4	0	0	=0
8	0	0	=0

16	0	0	=0
32	0	1	=32
64	1	1	=64
128	0	0	=0
			=96
This is why you add with |=. Both sides will combine all the activated(or whatever it's called? All the "1") bits into one larger array.
This is also why you check if a variable contains a certain bit with & because it will only return what both sides have in common.
__________________

Last edited by Black Rose; 08-15-2013 at 17:06.
Black Rose is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode