0
$\begingroup$

So I just recently came across a bitwise operation on StackOverflow which shifts the bits in a binary number to the right while zero-filling from the left. The left side zero-filling overwrites the sign bit, thus it always yields positive representations of a number (the result cannot be negative).

E.g.:

11010101 >>> 3

yields

00011010

According to the normal mathematical conventions for naming operators, would it be correct to call this an unsigned bitshift operator? I ask because it seems that this is not inherently an unsigned bitshift but just a zero-filling shift that overwrites (i.e. does not propagate) the sign bit. So, basically, it seems like although the result will always be unsigned it does not seem semantically correct to call the operator an unsigned bitshift operator. Another [lemma??] which I've run into that further supports the argument that this operator should not be called unsigned is that it can be used on both signed and unsigned operands.

$\endgroup$
  • $\begingroup$ It sometimes fill ones from the right if there was a 1 in the signed bit and sometimes it fills zeros, it's system dependant (at least in C). Also, AFAIK, it's called bit shift (to the right) operator (C again). $\endgroup$ – shinzou Jun 2 '15 at 19:03
  • $\begingroup$ Yeah that makes sense to me to call it bit shift (to the right). The documentation I linked to seems to also [correctly?] call it a "zero-fill right shift" operator. The main reason I asked the question is that I've found it in certain documentation where it is referred to as the unsigned right shift operator. $\endgroup$ – Alex W Jun 2 '15 at 20:01
0
$\begingroup$

Both $0$-filling and $1$-filling cases are referred to as bitshift operations. Calling the former an unsigned bitshift operator is ambiguous, as it is unclear what unsigned applies to (is it the bit, the bitshift, or the operator?).

If you want to make the description of the operator as unambiguous as possible, just use "unsigned bit-filling bitshift operator".

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.