Difference between '|' and '+' in bit manipulation -


i want use

00, 01, 10, 11 represent

a, b, c, d.

assuming have string, want express substrings length 5. can express

aaabb 0000000101.

now, have string s , integer mark used represent substring of s. when add b substring mark = mark<<2 | 1 question what's difference between mark = mark<<2 | 1 , mark = mark<<2 + 1

might depend on language using (please add tag next time!), typically operator precedence be: + << |

so comparing (mark << 2) | 1 , mark << (2+1). expect totally different results.

if question | (bitwise or) , + (addition), encourage learn each operator does, , come more specific question.

in case wondering: (mark << 2) | 1 , (mark << 2) + 1 return same result, because left-shift guarantees last bit zero.


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -