# How can I show base-2 long division?

I am writing a report in Latex and need to represent the CRC computation. So basically, I need to show the Paper-n-Pencil Method of Long Division in LaTeX.

Any idea how I can approach this problem ? Any good reference would be highly appreciated.

I plan to write similar thing in LaTeX.

-

## migrated from stackoverflow.comAug 28 '11 at 11:57

This question came from our site for professional and enthusiast programmers.

Did you ever figure this out? I am needing to do the exact same thing. – nw. Sep 20 '11 at 1:33
sorry, I couldn't do in latex atleast. I computed in the paper and developed it in inkscape – www.sapnaedu.in Sep 20 '11 at 12:31
OK, well I found somewhat of a solution, which I will post here for others' reference. It's not elegant (have to do the division by hand) but good enough for my purposes. – nw. Sep 20 '11 at 16:25


\newdimen\digitwidth
\settowidth\digitwidth{0}
\def~{\hspace{\digitwidth}}

\def\divrule#1#2{%
\noalign{\moveright#1\digitwidth%
\vbox{\hrule width#2\digitwidth}}}
101\,\begin{tabular}[b]{@{}r@{}}
10010 \\ \hline
\big)\begin{tabular}[t]{@{}l@{}}
1011110 \\
101 \\ \divrule{0}{7}
~~~111 \\
~~~101 \\ \divrule{3}{4}
~~~~100
\end{tabular}
\end{tabular}

You have to do the division by hand, then use '~'s for aligning the digits. For the little bars, do \divrule{startPosition}{length}.

Example output:

-
Thats so wonderful. I will try using the same approach. Thanks for sharing – www.sapnaedu.in Sep 20 '11 at 22:55

I've never used it myself, but you might try this package. It would likely require modification for binary, though.

There is also this post.

-