Raised This Month: $12 Target: $400
 3% 

[TUT] Bits, Bit-fields, and Bit-wise Operators


Post New Thread Reply   
 
Thread Tools Display Modes
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-08-2010 , 10:39   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #21

Then it would have been better, imo, to put 1 2 4 8 etc...
Event the great fysiks was confused
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-08-2010 , 12:17   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #22

Quote:
Originally Posted by ConnorMcLeod View Post
Then it would have been better, imo, to put 1 2 4 8 etc...
Event the great fysiks was confused
Not necessarily confused exactly, just wondered how it worked. If you initialize with 3 then the next would be 6, 12, 24, 48, etc.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-08-2010 , 13:06   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #23

Yesn enum works like this, take last value and apply the supplied ( +1 if not specified) operation.
That's why in that specific case ( <<=1 ), if you don't initialiaze first value to 1, then it's 0 and you 0<<1 == 0 so it can't work.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Zezima14
Member
Join Date: Feb 2010
Old 10-08-2010 , 13:21   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #24

Excuse my stupid question ...

I know that with the operator | can i increase bitsums values such as (1 <<1) | (1 <<2)
Exist another operator but to do the opposite of the operator |?, is say, to decreased bitsums?
Thanks all, and excuse my english.

PS: Thanks for the tut bugsy
Zezima14 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-08-2010 , 13:34   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #25

Quote:
Originally Posted by Zezima14 View Post
Excuse my stupid question ...

I know that with the operator | can i increase bitsums values such as (1 <<1) | (1 <<2)
Exist another operator but to do the opposite of the operator |?, is say, to decreased bitsums?
Thanks all, and excuse my english.

PS: Thanks for the tut bugsy
&~

See the Common bit-field operations section. Both are right next to eachother.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-08-2010 , 13:42   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #26

Connor, IMO, it is better to show the enum values as the value of one with a respective left shift since thats how bit sums are referred to throughout the tut. I do understand where you are coming from though and will add the respective X << 1 shift as well as keep what I have now.

Zezima, that is explained above, you use var &= ~( 1 << 2 )
__________________

Last edited by Bugsy; 10-08-2010 at 16:20.
Bugsy is offline
Zezima14
Member
Join Date: Feb 2010
Old 10-08-2010 , 15:13   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #27

Quote:
Originally Posted by Bugsy View Post
Connor, IMO, it is better to show the enum values as the value of one with a respective left shift since thats how bit sums are referred to throughout the tut. I do understand where you are coming from though and will add the respective X << 1 shift as well a keep what I have now.

Zezima, that is explained above, you use var &= ~( 1 << 2 )
im very stupid for this u.u

if i wanna decreased 8 - 1 with bitsums, how can i make this ? :p

Result |= ( 1 << 3 ) & ~( 1 << 0 )
Zezima14 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-08-2010 , 15:21   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #28

Quote:
Originally Posted by Zezima14 View Post
if i wanna decreased 8 - 1 with bitsums, how can i make this ? :p

Result |= ( 1 << 3 ) & ~( 1 << 0 )
What are you asking?
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-08-2010 , 15:24   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #29

8 = 1 << 3
1 = 1 << 0
8 = 1000
1 = 0001

7 = 1 << 0 | 1 << 1 | 1 << 2
7 = 0111

You could get 7 by doing ~8 but each situation will be different. You can't do addition or substation by 1 like that if thats what youre trying to do
__________________

Last edited by Bugsy; 10-08-2010 at 15:45.
Bugsy is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 10-08-2010 , 20:35   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #30

8-1
Seta00 is offline
Reply


Thread Tools
Display Modes

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 10:37.


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