1

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

  • 1
    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
1

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}

enter image description here

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.