4 ms·
<< means shift left (moves the bits to the left side) 1 << 1 = 2 because (0001 << 1 = 0010 = 2) 3 << 1 = 6 because (0011 << 1 = 0110 = 6) >> works in the sam
by denysvitali 5y ago
<< means shift left (moves the bits to the left side)
1 << 1 = 2 because (0001 << 1 = 0010 = 2)
3 << 1 = 6 because (0011 << 1 = 0110 = 6)
>> works in the same way
2 >> 1 = 1 because (0010 >> 1 = 0001)
The other operators are exactly the same you'd find in electronics (and boolean algebra):
~ is the NOT operator
& is the AND operator
^ is the XOR operator
Sorry, I don't have a visual representation for this (I haven't looked for a link) but I would strongly suggest to write it down on paper and do some small exercises (checking with the result then on your favorite programming language).
On a day to day basis, you'd likely not use these operators at all, but as soon as you start decoding protocols or working on a bit-level, those are super useful!
I would suggest trying to decode a bitstream protocol to really grasp the concepts: you'd use masks and bitwise operators a lot :)
---
Edit: some useful links I've found:
https://www.interviewcake.com/concept/java/bit-shift https://www.interviewcake.com/concept/java/bit-shift
- rzzzt 5y agoRight shift can get tricky for negative numbers. There are two operators for it, one which respects the sign bit, the other does not: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- ElectronCharge 5y agoTesting…