-3

I understand all of the bitwise operations (in Java specifically) except bitwise left shift. I've combed the "stacks" and read many "explanations" on different pages, but I am still left unsatisfied. Either this is an extremely complicated concept or it is not well understood and obscure. But, I know it must be relevant to some extent because I have seen Java algorithms (today) that indeed use the left shift operator "<<". So if someone could break this down in plain English that would be great!

Dimpermanence
  • 47
  • 1
  • 9
  • 9
    You understand both right shifts but not left shift? – khelwood Jan 29 '16 at 15:02
  • @khelwood Even though I could surmise what you're implying, life is better if you just say how you feel the first time without speaking in code... – Dimpermanence Jan 29 '16 at 15:05
  • 2
    I am not implying anything. I am puzzled by your assertion that you understand all the other bitwise operations (which logically must include right shift) but you don't understand left shift enough even to ask a specific question about it. I want to verify that you understand right shift, because that knowledge will make it easier to explain left shift. – khelwood Jan 29 '16 at 15:07
  • @Mishax Aaaaand Bob's my uncle. Thanks for the link. That relieved all of my unpleasant confusion : ) Don't know why I couldn't find it myself but I'm grateful for that excellent post. Thanks! – Dimpermanence Jan 29 '16 at 15:13
  • Brutal downvote! Hilarious! I hope everyday has a great day : ) – Dimpermanence Jan 29 '16 at 15:18

1 Answers1

0

left shift by one bit moves all the bits in the value one bit position to the left. The position that gets free at the right side is filled with bit 0, the bit that was farmost left is lost.

This is the same effect as multiplying the value by 2.

Example (using just 8 bits for simplicity):

original value     10010011
after shift left   00100110

If you shift left by n bits, just repeat that n times (provided n is smaller than the word length). For n larger than the word length shift by n % wordLength.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • Isn't there more to it than that though? Aren't there certain conditions where the value of the number can become undefined, etc.? – Dimpermanence Jan 29 '16 at 15:06
  • Me thinks I may have overthought this. Oh well! Thanks Henry. This is definitely a duplicate but I'm selecting your response as the correct answer. – Dimpermanence Jan 29 '16 at 15:12