Raised This Month: $ Target: $400
 0% 

Negative shifting bitsum.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-17-2017 , 15:33   Negative shifting bitsum.
Reply With Quote #1

Dose negative bitsums shifting works?

For example

PHP Code:

new bitsum |= (1<<-1)    will be equal to 1/)
                     (
1<<-2)   and this will equal to 1/

ID'S

Code:
ID      :-         -2    -1      0      1      2  
VALUE :-        (1/4)    (1/2)      1      2      4




Or this is how it works :- by shifting to the right (1>>0) = 1/2 = 0.5
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 04-17-2017 at 15:55.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-17-2017 , 15:47   Re: Negative bitsum.
Reply With Quote #2

In C it's undefined behavior, and since Pawn's left shift directly translates to C's, it should be undefined behavior too.

Last edited by klippy; 04-17-2017 at 15:48.
klippy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-17-2017 , 15:56   Re: Negative bitsum.
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
In C it's undefined behavior, and since Pawn's left shift directly translates to C's, it should be undefined behavior too.
thanks for the fast response.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 04-17-2017 , 19:48   Re: Negative shifting bitsum.
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
(1>>0) = 1/2 = 0.5
(x>>0) = x
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-18-2017 , 10:28   Re: Negative shifting bitsum.
Reply With Quote #5

Quote:
Originally Posted by PRoSToTeM@ View Post
(x>>0) = x
so whats the point of shifting right?

and what about (x>>1) = ? what dose it equal to?

&&

btw shifting negative gives results, it dosen't throw an error! (1<<-1) & (1<<0) = 0
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 04-18-2017 at 10:35.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-18-2017 , 10:49   Re: Negative shifting bitsum.
Reply With Quote #6

There's applications of right shifting, it's the opposite of left shifting. Can't think of any right now but I've been using it.

I never said it will throw an error, it's just undefined behavior - the result is not defined by the standard.

Last edited by klippy; 04-18-2017 at 10:49.
klippy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-18-2017 , 12:23   Re: Negative shifting bitsum.
Reply With Quote #7

Quote:
Originally Posted by KliPPy View Post
There's applications of right shifting, it's the opposite of left shifting. Can't think of any right now but I've been using it.

I never said it will throw an error, it's just undefined behavior - the result is not defined by the standard.
what i meant its not bad to use negative shifting .
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-18-2017 , 12:42   Re: Negative shifting bitsum.
Reply With Quote #8

Hence there is no reason to do it. If you shift negative places then your code has a flaw and you should fix it.
klippy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-18-2017 , 15:05   Re: Negative shifting bitsum.
Reply With Quote #9

Quote:
Originally Posted by KliPPy View Post
Hence there is no reason to do it. If you shift negative places then your code has a flaw and you should fix it.
i am using it like a null just for ignorance!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



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 18:01.


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