Zero-fill right shift operator

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Zero-fill right shift operator

Post by wilbert »

Can we have a zero-fill right shift operator like JavaScript has ?

Code: Select all

>>   Sign-propagating right shift
>>>  Zero-fill right shift
It wouldn't break compatibility with current code and would be a huge benefit when converting code from other languages.
Windows (x64)
Raspberry Pi OS (Arm64)
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Zero-fill right shift operator

Post by Little John »

Yes, please! :-)
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: Zero-fill right shift operator

Post by PureGuy »

+1
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Zero-fill right shift operator

Post by Danilo »

Actually, that's just an unsigned shift and should already work with '>>' and unsigned .a + .u data types.

So the question is, do you need an unsigned shift operator like '>>>', or do you need
more unsigned data types (32bit and 64bit)?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Zero-fill right shift operator

Post by wilbert »

Danilo wrote:So the question is, do you need an unsigned shift operator like '>>>', or do you need
more unsigned data types (32bit and 64bit)?
Both can be good.

If you want to rotate the bits of a signed integer by OR-ing a shift left and a shift right, you will need a zero-fill right shift.
In this case the extra operator would be nice, even on signed types.

Of course the reason I asked has also to do with porting code that uses unsigned integers.
Additional unsigned types have been asked for many times before and have never been implemented.
Having at least a zero-fill right shift operator will help a lot to work around the limitation of not having those unsigned types and is maybe easier to implement.
Windows (x64)
Raspberry Pi OS (Arm64)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Zero-fill right shift operator

Post by davido »

+1
DE AA EB
Post Reply