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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -