Page 1 of 1

Zero-fill right shift operator

Posted: Wed Aug 19, 2015 6:54 am
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.

Re: Zero-fill right shift operator

Posted: Wed Aug 19, 2015 7:01 am
by Little John
Yes, please! :-)

Re: Zero-fill right shift operator

Posted: Mon Aug 24, 2015 11:49 am
by PureGuy
+1

Re: Zero-fill right shift operator

Posted: Tue Aug 25, 2015 5:43 am
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)?

Re: Zero-fill right shift operator

Posted: Tue Aug 25, 2015 5:56 am
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.

Re: Zero-fill right shift operator

Posted: Tue Aug 25, 2015 2:10 pm
by davido
+1