# Print binary number with spacing

I've been trying to print a binary number with a small space, automatically, every four digits. Starting from right and moving to the left.

I found this package that allowed me to achieve this, but unfortunately, it requires me to add a

0b


in front of each number. I'd rather not print out this at all, as I use a

$_2$


Can someone help me use this package and not print out

0b


or a different way to achieve this? Thanks

• I found in a related question the package siunitx, it seems that there is an option called group-four-digits that solves what you need, maybe you should check that out. – Laura Paola Gamboa Oct 7 '19 at 2:22

There are probably other ways, but this one (inspired by this answer) seems to work.

\documentclass{article}
\usepackage{soul}
\newcounter{binst}
\makeatletter
\newcommand{\FormatBinary}[1]{\begingroup%
\setcounter{binst}{0}
\def\SOUL@soeverytoken{%
\stepcounter{binst}%
\ifnum\value{binst}=5\relax%
\setcounter{binst}{1}\,%
\fi%
\the\SOUL@token}%
\so{#1}\endgroup}
\makeatother
\begin{document}
\FormatBinary{100100010010}
\end{document}


• Hey, this works perfectly! Thank you so much! After I'm done making my document, I'm going to go through this and ask some followup questions so I can understand why this works. Thank you! – Greg Hilston Oct 7 '19 at 2:21