8
$\begingroup$

There are many symbols available in MathJax / $\TeX$.

How can I format the common bitwise operations using the formatting available on this site?

$\endgroup$
1
  • $\begingroup$ I've added a similar Q&A especially for the different ways to invoke math-mode and use it to format math code. $\endgroup$
    – SEJPM
    Commented Dec 20, 2016 at 16:52

1 Answer 1

9
$\begingroup$

There are no direct choices for bitwise operators. We have however a few options in this regard, taken from the logical set of operators:

XOR (exclusive OR):

  • the symbol $\oplus$ can be created using \oplus
  • the symbol $\otimes$ can be created using \otimes

NEG (negation):

  • the symbol $\sim$ can be created using \sim
  • the symbol $\neg$ can be created using \neg

AND (bitwise AND):

  • the symbol $\land$ can be created using \land (logical-AND) or \wedge (but note that ^ is often used to mean XOR in programming languages)
  • the symbol $\&$ can be created using \&

OR (bitwise OR):

  • the symbol $\lor$ can be created using \lor (logical-OR) or \vee
  • the symbol $\circ$ can be created using \circ
  • the symbol $|$ can simply be created using a single pipe character |
  • the symbol $\parallel$ can be created using \parallel

The shift and round functions can also be formatted:

  • $\ll$ means left-shift and can be created using \ll
  • $\lll$ means left-rotation and can be created using \lll
  • $\gg$ means right-shift and can be created using \gg
  • $\ggg$ means right-rotation and can be created using \ggg

To display these symbols put them in formulas between one \$ sign (inline formula) or two \$\$ signs (centered formula on a separate line). So $a \oplus b$ displays as $a \oplus b$ while $$a \oplus b$$ displays as: $$a \oplus b$$


Of these the $\oplus\space\&\space\circ$ are probably the ones least reused. Sometimes $+$ (just +) and $\cdot$ (\cdot) are also used in functions to mean OR and AND respectively.

Alternatively it is possible to use $\operatorname{or}$ directly by using \operatorname{or}, which simply displays the text as if it was a function identifier. This will arguably introduce the least confusion.


This answer just shows how to format bitwise operators. It doesn't show any reason to choose one over the other (unless confusion can arise), it's just used to display the various formatting options.

As you can see, there are many options to choose from. Please make sure we understand the meaning of each operator that you use. 🦉

$\endgroup$
5
  • 1
    $\begingroup$ Or just $a \operatorname{or} b$ $\endgroup$
    – CodesInChaos Mod
    Commented Dec 20, 2016 at 11:39
  • $\begingroup$ @CodesInChaos Added option for \operatorname. By the way, if you know how to use \newcommand at the top of the document without introducing whitespace... Currently you get whitespace if you use a carriage return at the end of the MathJax definition. $\endgroup$
    – Maarten Bodewes Mod
    Commented Dec 20, 2016 at 12:58
  • $\begingroup$ I don't know what happened, but this post was supposed to be "community wiki" - now it is again, wiki away on it everyone! $\endgroup$
    – Maarten Bodewes Mod
    Commented Dec 20, 2016 at 18:54
  • $\begingroup$ Is there a source with all of the symbols? $\endgroup$
    – winklerrr
    Commented Jun 24, 2019 at 20:37
  • $\begingroup$ Trust me, you don't wan't all $\TeX$ symbols. There is this other post, and this post that is much more extensive. Or, for symbols, try the Detexify app. Are you looking for something in particular? $\endgroup$
    – Maarten Bodewes Mod
    Commented Jun 25, 2019 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .