Raised This Month: $32 Target: $400
 8% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-07-2010 , 01:40   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #11

By the time they have gotten to the bottom of the tutorial, they will realize that the 6th bit becoming the 1st bit (5 bit shift left) will be the value from 32 and above since you have a list up at the top where 2^6 = 32 so they should understand bit shifts and even if it does give a bit of confusion it's better for them to reread so they understand or even ask questions rather than withholding information.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 10-07-2010 , 09:42   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #12

number << X = number * 2^X
number >> X = number / 2^X

And they are faster than normal math operations.
Seta00 is offline
Lt.RAT
Member
Join Date: Sep 2008
Location: Russia Yekaterinburg
Old 10-07-2010 , 14:45   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #13

a1 >> a2 - arithmetic shift to the right of a1 by a2 bits;
a1 >>> a2 - logical shift to the right of a1 by a2 bits;
and
a1 << a2 - a1 shifted to the left by a2 bits; No distinction between
an arithmetic and a logical left shift.


PS division - slowest "base" operation in PC, multiply - slower than shift too, so they should be changed with shift left/rigth when possible.
Lt.RAT is offline
Send a message via ICQ to Lt.RAT
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-07-2010 , 16:03   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #14

Nice quote from the pawn language guide I will add an explanation of the difference between logical and arithmetic shifting.
__________________
Bugsy is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 10-07-2010 , 22:09   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #15

Ohhh noo maths again, damn
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 10-08-2010 , 00:06   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #16

Thnx, For this tutorial ... now i will use bits instead of 33 cell arrays !
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-08-2010 , 01:31   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #17

You enum could be confusing :

Code:
//Create a list of options that are supported by the plugin enum ( <<=1 ) _: Options {     Speed=1,   // 1 << 0     AutoAim,   // 1 << 1     HighJump,  // 1 << 2     ExtraHP,   // 1 << 3     ExtraArmor // 1 << 4 }

Comments are not true, each value is the last value shift by 1, correct comments should be :

Code:
enum ( <<=1 ) _: Options {     Speed=1,    // 1            // 1     AutoAim,    // 1 << 1    // 2     HighJump,   // 2 << 1    // 4     ExtraHP,    // 4 << 1    // 8     ExtraArmor  // 8 << 1    // 16 }

Results are the same though, but it makes it easier to understand how it works and why you have to set first enum to 1.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 10-08-2010 at 01:34.
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-08-2010 , 02:07   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #18

Thanks Connor, I was wondering how that worked exactly.
__________________
fysiks is offline
g_often
Senior Member
Join Date: Jan 2010
Location: In your mind
Old 10-08-2010 , 09:11   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #19

Thanks Bugsy
__________________
Reality is wrong, dreams are for real.
g_often is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-08-2010 , 09:46   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #20

Quote:
Originally Posted by ConnorMcLeod View Post
You enum could be confusing :

Code:
//Create a list of options that are supported by the plugin enum ( <<=1 ) _: Options {     Speed=1,   // 1 << 0     AutoAim,   // 1 << 1     HighJump,  // 1 << 2     ExtraHP,   // 1 << 3     ExtraArmor // 1 << 4 }

Comments are not true, each value is the last value shift by 1, correct comments should be :

Code:
enum ( <<=1 ) _: Options {     Speed=1,    // 1            // 1     AutoAim,    // 1 << 1    // 2     HighJump,   // 2 << 1    // 4     ExtraHP,    // 4 << 1    // 8     ExtraArmor  // 8 << 1    // 16 }

Results are the same though, but it makes it easier to understand how it works and why you have to set first
My comments were intended to show the value in each constant, not the enum operation occurring.
__________________

Last edited by Bugsy; 10-08-2010 at 10:10.
Bugsy 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 01:05.


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