czardas Posted September 25, 2012 Posted September 25, 2012 (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? It appears inconsistant (default) behaviour, to me at least. Edited September 25, 2012 by czardas operator64 ArrayWorkshop
dany Posted September 25, 2012 Posted September 25, 2012 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 czardas 1 [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF
czardas Posted September 25, 2012 Author Posted September 25, 2012 (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 September 25, 2012 by czardas operator64 ArrayWorkshop
czardas Posted September 26, 2012 Author Posted September 26, 2012 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. operator64 ArrayWorkshop
jvanegmond Posted September 26, 2012 Posted September 26, 2012 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. github.com/jvanegmond
czardas Posted September 26, 2012 Author Posted September 26, 2012 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. operator64 ArrayWorkshop
Richard Robertson Posted September 26, 2012 Posted September 26, 2012 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.
jvanegmond Posted September 26, 2012 Posted September 26, 2012 (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 September 26, 2012 by Manadar github.com/jvanegmond
czardas Posted September 26, 2012 Author Posted September 26, 2012 (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. Lisp also uses a positive value for left shift. Edited September 26, 2012 by czardas operator64 ArrayWorkshop
czardas Posted September 26, 2012 Author Posted September 26, 2012 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! operator64 ArrayWorkshop
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now