yank '>>>'?

Ellery Newcomer ellery-newcomer at utulsa.edu
Sun Dec 6 09:16:35 PST 2009


On 12/06/2009 10:11 AM, Andrei Alexandrescu wrote:
> D has operator >>> which means "unsigned shift to the right", inherited
> from Java. But it doesn't need it because D has unsigned types, which
> can be used to effect unsigned shift. (Java, lacking unsigned types, had
> no other way around but to define a new operator.)
>
> Should we yank operator>>>?
>
>
> Andrei

taking the opportunity to review what the difference is between >> and >>>

for signed integers, >> is equivalent to divide by 2. It leaves the sign 
bit unchanged. >>> is an actual bit shift. Neither moves the lower n 
bits to the upper n bits or anything like that.

for unsigned integers, >> is equivalent to divide by 2. >>> is an actual 
bit shift, but that's equivalent to divide by 2, so >> and >>> are the same.

I've never liked that >> doesn't actually shift all of the bits, and the 
only valid use for it is equivalent to

a / 2^^n

except less readable. Although I don't suppose one should be doing 
bitwise manipulations with signed integers in the first place..



More information about the Digitalmars-d mailing list