Jump to content

Bit of a Mix Up


czardas
 Share

Recommended Posts

The shift value for BitShift is described as: (the) Number of bits to shift to the right (negative numbers shift left).

BitRotate description gives: Performs a bit shifting operation, with rotation.

The shift value for BitRotate is described as: (the) Number of bits to rotate to the left (negative numbers shift right).

I noticed this apparent inconsistancy recently after so my question is this: Is there a hidden deeper meaning to this, or is it just a bit of mix up? :tv_horror:

It appears inconsistant (default) behaviour, to me at least.

Edited by czardas
Link to comment
Share on other sites

mmh, imho it's inconsistent behavior too...

But in Haskell positive numbers shift and rotate to the left, whereas in MathLab it's the other way around, atleast for the bitshift function it is. Most languages use << and >> operators which arn't as implementation dependent or ambiguous.

So yea... You could just say that AutoIt has character, like wine :)

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

After some reflection, I have formed the opinion that if there was such a thing as a default direction for positive shift then it ought to be to the left. My reasoning is based on the idea that a positive shift would then double the input value, and a negative shift would diminish it by half. The idea of a positive shift returning a greater value seems logical.

Link to comment
Share on other sites

After some reflection, I have formed the opinion that if there was such a thing as a default direction for positive shift then it ought to be to the left. My reasoning is based on the idea that a positive shift would then double the input value, and a negative shift would diminish it by half. The idea of a positive shift returning a greater value seems logical.

That wholly depends on where your MSB and LSB are. Bits are abstract.
Link to comment
Share on other sites

I thought the MSB was generally the first (most right hand) bit. I think logical and arithmetic shift ought to both have the same default direction. It makes sense to have all numeric base systems increment from right to left - as they are generally written. If the expression has a non-numeric interpretation then the whole concept of positive and negative shift is redundant I suppose.

Link to comment
Share on other sites

I thought the MSB was generally the first (most right hand) bit. I think logical and arithmetic shift ought to both have the same default direction. It makes sense to have all numeric base systems increment from right to left - as they are generally written. If the expression has a non-numeric interpretation then the whole concept of positive and negative shift is redundant I suppose.

MSB stands for most significant bit. That means the bit that has the most significant sway in the value. This would be the sign bit or the highest value bit.

Yes, what Richard says. Don't think of bits as logically going from right-to-left or left-to-right. If you need to identify bits, talk about MSB and LSB. Bits are generally written right-to-left, but in industry / academia its also often reversed. If you'd work with software at a lower level or design some digital hardware, you'll more easily understand the importance of this.

Bits with a non-numeric interpretation (I assume you mean integer here, otherwise doesn't make sense) still have logical applications to be shifted. For example in encryption or in fast inverse square root. Linkie: http://en.wikipedia.org/wiki/Fast_inverse_square_root

Edited by Manadar
Link to comment
Share on other sites

I said non-numeric so as to avoid making the false assumption that any of the components which make up a float would read in the opposite direction. However my argument for positive shift to the left does partly revolve around the resulting effect on integers. I also conducted a thought experiment: When you scroll down a page, the text at the top of the screen disappears out of view. Now rotate your screen 90 degrees counterclockwise while scrolling, and the text moves off the screen to the left. These are the default directions for rolling film credits and horizontal scrolling text. Positive shift => Go to the next bit, item, word, line of text. enz. Negative shift => Go back.

I suppose it's the other way around if you're Chinese.

:think:

Lisp also uses a positive value for left shift.

Edited by czardas
Link to comment
Share on other sites

Thanks for your responces. I'm thinking of ignoring my intuition in this case and stop worrying too much about consistancy. There are valid reasons to leave things exactly as they are, and in doing so relinquish any responsibility for getting it backwards. Probably nobody is ever going to bat an eyelid. Superfluous detail!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...