It would be nice to have a binary shift

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
infratec
Always Here
Always Here
Posts: 7779
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

It would be nice to have a binary shift

Post by infratec »

Up to now I never needed an arithmetic shift.
I always need a binary shift.

So it would be nice to have such a function available.
User_Russian
Addict
Addict
Posts: 1619
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: It would be nice to have a binary shift

Post by User_Russian »

There are many such requests on the forum.
viewtopic.php?t=77286
viewtopic.php?t=52929

I never needed an arithmetic shift. Logical shift was always needed, but PB doesn't support it, so I wrote the code in assembler.
threedslider
Enthusiast
Enthusiast
Posts: 562
Joined: Sat Feb 12, 2022 7:15 pm

Re: It would be nice to have a binary shift

Post by threedslider »

We need something like that :

Code: Select all

a = 1
n = 2

o = a Or (1 << n)

Debug o
Only working in conditional logic ... :|
User avatar
idle
Always Here
Always Here
Posts: 6171
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: It would be nice to have a binary shift

Post by idle »

Yes +1 but what we really need is unsigned types then the compiler can choose between logical and arithmetic shift based on the type
easy for the c backend as you only need to cast required variables to unsigned
and for asm backend I think this is all that's required to enable unsigned
viewtopic.php?t=65312
threedslider
Enthusiast
Enthusiast
Posts: 562
Joined: Sat Feb 12, 2022 7:15 pm

Re: It would be nice to have a binary shift

Post by threedslider »

However it works like this :

Code: Select all

a = 1
n = 2

o = a | (1 << n)

Debug o
there is separate from the | and Or :shock:
threedslider
Enthusiast
Enthusiast
Posts: 562
Joined: Sat Feb 12, 2022 7:15 pm

Re: It would be nice to have a binary shift

Post by threedslider »

idle wrote: Mon Jan 26, 2026 10:36 pm Yes +1 but what we really need is unsigned types then the compiler can choose between logical and arithmetic shift based on the type
easy for the c backend as you only need to cast required variables to unsigned
and for asm backend I think this is all that's required to enable unsigned
viewtopic.php?t=65312
Nice code ! Thanks for sharing :)
Post Reply