+ 3
Is bitwise the hardest operations to make/understand in general programmming?
Currently this is a concept I can't figure out. And for you?
2 Answers
+ 5
Hi Lucas... I recently posted an explanation to a specific bitwise problem. I think the key to understanding bitwise is to understand how booleans work. Hopefully this answer will help with this understanding somewhat.
https://www.sololearn.com/Discuss/1006700/need-a-little-help-in-bitwise-operators
+ 3
While I don't think it's the hardest concept, I understand how it can be difficult to understand. Perhaps it would be easier if you thought of it as an "array" of 8 (or 16, 32, ...) boolean values. Each operation you perform on the "array" is performed on each of the values.
0011 & 0101 = 0001 because, in order:
false && false = false (0 & 0 = 0)
false && true = false (0 & 1 = 0)
true && false = false (1 & 0 = 0)
true && true = true (1 & 1 = 1)
Bitshifting is just moving the bits in the "array" to the left or to the right. The spots on the ends don't wrap around to the other side, but instead get 0s because there was no value to move into that spot.
1111 shifted left = 1110
1111 shifted right = 0111