AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Negative shifting bitsum. (https://forums.alliedmods.net/showthread.php?t=296314)

Natsheh 04-17-2017 15:33

Negative shifting bitsum.
 
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

klippy 04-17-2017 15:47

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

Natsheh 04-17-2017 15:56

Re: Negative bitsum.
 
Quote:

Originally Posted by KliPPy (Post 2513035)
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.

PRoSToTeM@ 04-17-2017 19:48

Re: Negative shifting bitsum.
 
Quote:

Originally Posted by Natsheh (Post 2513027)
(1>>0) = 1/2 = 0.5

(x>>0) = x

Natsheh 04-18-2017 10:28

Re: Negative shifting bitsum.
 
Quote:

Originally Posted by PRoSToTeM@ (Post 2513096)
(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

klippy 04-18-2017 10:49

Re: Negative shifting bitsum.
 
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.

Natsheh 04-18-2017 12:23

Re: Negative shifting bitsum.
 
Quote:

Originally Posted by KliPPy (Post 2513253)
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 .

klippy 04-18-2017 12:42

Re: Negative shifting bitsum.
 
Hence there is no reason to do it. If you shift negative places then your code has a flaw and you should fix it.

Natsheh 04-18-2017 15:05

Re: Negative shifting bitsum.
 
Quote:

Originally Posted by KliPPy (Post 2513295)
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!


All times are GMT -4. The time now is 18:01.

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