logical shift

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

logical shift

Post by User_Russian »

At this point, in PureBasic, there is only an arithmetic shift, but would not hurt to add and logical shift. The situation is complicated by the fact that there is no unsigned variables.
The example shows that the arithmetic shift results in an error.

Code: Select all

x=-1
x>>4
Debug x
Debug RSet(Hex(x, #PB_Long), 8, "0")
Logical shift gives the correct result even with a signed variable.

Code: Select all

EnableASM

x=-1

mov eax, x
shr eax, 4
mov x, eax

Debug x
Debug RSet(Hex(x, #PB_Long), 8, "0")
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: logical shift

Post by Olliv »

Here, wilbert suggests more recently using javascript syntax to add and dicern both functions.

I move up this wish to hope see both shift function, and in the way anybody finds a best syntax.
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: logical shift

Post by User_Russian »

The C backend provides an easy way to logically shift signed variables.

Code: Select all

x.l=$80000000
Debug RSet(Bin(x, #PB_Long), 32, "0")
x>>16
Debug RSet(Bin(x, #PB_Long), 32, "0")

x.l=$80000000
Debug RSet(Bin(x, #PB_Long), 32, "0")
!v_x = (unsigned long)v_x >> 16;
Debug RSet(Bin(x, #PB_Long), 32, "0")
Post Reply