AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [TUT] Bits, Bit-fields, and Bit-wise Operators (https://forums.alliedmods.net/showthread.php?t=139916)

ConnorMcLeod 10-08-2010 10:39

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
Then it would have been better, imo, to put 1 2 4 8 etc...
Event the great fysiks was confused :mrgreen:

fysiks 10-08-2010 12:17

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
Quote:

Originally Posted by ConnorMcLeod (Post 1318983)
Then it would have been better, imo, to put 1 2 4 8 etc...
Event the great fysiks was confused :mrgreen:

Not necessarily confused exactly, just wondered how it worked. If you initialize with 3 then the next would be 6, 12, 24, 48, etc.

ConnorMcLeod 10-08-2010 13:06

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
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.

Zezima14 10-08-2010 13:21

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
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:)

fysiks 10-08-2010 13:34

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
Quote:

Originally Posted by Zezima14 (Post 1319154)
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.

Bugsy 10-08-2010 13:42

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
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 )

Zezima14 10-08-2010 15:13

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
Quote:

Originally Posted by Bugsy (Post 1319179)
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 )

fysiks 10-08-2010 15:21

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
Quote:

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

Result |= ( 1 << 3 ) & ~( 1 << 0 )

What are you asking?

Bugsy 10-08-2010 15:24

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
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

Seta00 10-08-2010 20:35

Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
 
8-1 :|


All times are GMT -4. The time now is 23:02.

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