Page 1 of 1

logical shift

Posted: Wed Jan 16, 2013 10:16 am
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")

Re: logical shift

Posted: Sat Jun 24, 2017 6:54 pm
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.

Re: logical shift

Posted: Thu May 20, 2021 8:18 pm
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")