Sign in to follow this  
Followers 0
czardas

Bit of a Mix Up

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 :)

1 person likes this

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for your informed responce dany. Now I know at least it's nothing I missed. There seems to be no across-the-board universal behaviour. Using << and >> is very easy to understand.

Edited by czardas

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
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!

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • quickbeam
      By quickbeam
      The BitShift funtion apparently does sign extension for 32-bit numbers if the MSb is set.  Is there any way to turn that off and do real (C style) bit shifts?
       
    • czardas
      By czardas
      I found a bit of time today to write something, after criticism that people chatting don't write enough code. Well it's perhaps an old school concept, but I wanted to solve it myself. Logical shift on an infinite hex string. Well not really infinite, but it might as well be compared to the small 32/64-bit versions. Please note: it only shifts bits once. If you want an actual infinite shift value (not really recommended) then use a while loop.
      Theoretically the code should run faster without calls to Int() , but this appears to be an unfortunate consequence of unfinished development. Don't ask me why that is, because I don't have an answer. Anyway forget that! This function might have been more useful to me about a year ago, but it was fun to figure out how to do it today anyway.
      IMPROVED VERSION IN >POST 8
      ;
      Original code