I asked the following in a letter to Donald Knuth:
Lastly, I started to use your CWEB system for a project to find out if literate programming is a style that suits me. So far, I like it very much! The only problem I am experiencing is that I haven't found a way yet to mention the bitwise-or operator | within a c-section. Is there special syntax for that or do I have to use
kludges tricks with @t?
He gave this answer:
Amazingly – after thousands of programs of which more than 100 must surely use bitwise or – I've never felt the need for that operator inside a comment! (I do have \vert defined in plain.tex so that I don't need | in math much.)
There really is no way to “fool” the parser in ctangle/cweave, hence one cannot expect to just type any C code that includes the ‘|’ character. [That means || is problematic too]. My natural inclination, if I wanted ‘x|y’ within TEX code, would be $|x|\OR|Y|$ using the \OR from cwebmac.tex. [Actually I use different spacing in TAOCP …
bitwise AND is \mathchardef\band="2026
but \OR = \mid in cwebmac].
If you need it more often or in quite general contexts, the best kludge I can think of is to substitute another binary operator that you aren't using, and let TEX make the switch:
Look at |x%y| and \bitor|x%y|! for example.
comes out as
Look at x % y and x | y for example.