1

Does exist package by which I will be able to reproduce the following long division procedure used binary arithmetic?

enter image description here

I look to longdivision package but I didn't find a way how to convinced it to use binary arithmetic instead of decimal.

Or for this is only way to draw it by tikz or write as table, for example?

As you can see, showed image is bad quality, so just copy them is out of question. Beside of this example, I need to draw many other ones.

Zarko
  • 296,517
  • 1
    This is for multiplication https://tex.stackexchange.com/questions/136970/typesetting-binary-arithmetic?noredirect=1&lq=1 If you store each row in a seq, reverse and pronto:) Once you can do school book math ops, you can do bigNum operations so the results can be book length:). To be honest personally I would use Lua so the results can be checked in base10 easily (if it involves big numbers). But l3 also can do. – yannisl Mar 10 '24 at 01:40
  • 1
    @yannisl, thank you very much for info. Meantime i somehow convinced myself, that write division manually is not so terrible ... David's way to do this seems to be good starting points. Unfortunately I'm not familiar with Lua :-) – Zarko Mar 10 '24 at 11:30
  • Good idea, please post an answer as well, when you are done. – yannisl Mar 10 '24 at 11:43

2 Answers2

2

Showed image is part of explanation how channel coding works with using of CRC.

I have imagined, that in package \longdivision for computation of long division has build in some module for calculations with decimal numbers and that this module can be replaced with module, which perform binary calculation. It seems, that for this problem only me or few people are interested for this.

Since I'm not skilled to write a LaTeX package code, and I need to finish other part of textbook, I left my experimenting for summer or autumn, when (hopefully I will finish temporary project.

So I decide for temporary solution write long division by hand using tabularray package for writing of table:

\documentclass[border=1mm, 11pt]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
%---------------------------------------------------------------%

\begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \SetTblrInner{colsep=1pt, rowsep=0.5pt, stretch=-1, cells = {font=\footnotesize}, cell{odd[2-Z]}{18} = {l, bg=gray!10}, cell{2-Z}{14-17} = {fg=blue}, hline{2}={6-17}{0.5pt}, hline{3}={5-5}{0.5pt}, vline{6}={2}{0.5pt}, vline{14}={2-Z}{dashed,0.5pt} } %---------------------------------------------------------------% \begin{tblr}{colspec={*{17}{Q[c,mode=math]} Q[r, fg=black!70, font=\tiny, mode=math, leftsep=6pt] }, cell{odd[2-Z]}{18} = {l}, } & & & & & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & \
1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 1<11001 \ & & & & - & 0 & & & & & & & & & & & & \gets 0{\cdot}11001 \
\cline{6-7} & & & & & 1 & 1 & & & & & & & & & & & 11<11001 \ & & & & - & 0 & 0 & & & & & & & & & & & \gets 0{\cdot}11001 \
\cline{6-8} & & & & & 1 & 1 & 1 & & & & & & & & & & 111<11001 \
& & & & & - & 0 & 0 & & & & & & & & & & \gets 0{\cdot}11001 \ \cline{6-9} & & & & & 1 & 1 & 1 & 0 & & & & & & & & & 1110<11001 \
& & & & - & 0 & 0 & 0 & 0 & & & & & & & & & \gets 0{\cdot}11001 \
\cline{6-10} & & & & & 1 & 1 & 1 & 0 & 0 & & & & & & & & 11100>11001 \
& & & & - & 1 & 1 & 0 & 0 & 1 & & & & & & & & \gets 1{\cdot}11001 \
\cline{6-11} & & & & & 0 & 0 & 0 & 1 & 1 & 1 & & & & & & & 111<11001 \
& & & & & - & 0 & 0 & 0 & 0 & 0 & & & & & & & \gets 0{\cdot}11001 \
\cline{6-12} & & & & & & 0 & 0 & 1 & 1 & 1 & 1 & & & & & & 1110<11001 \
& & & & & & - & 0 & 0 & 0 & 0 & 0 & & & & & & \gets 0{\cdot}11001 \ \cline{8-13} & & & & & & & 0 & 1 & 1 & 1 & 1 & 0 & & & & & 11110>11001 \
& & & & & & & - & 1 & 1 & 0 & 0 & 1 & & & & & \gets 1{\cdot}11001 \
\cline[fg=red]{9-14} & & & & & & & & 0 & 0 & 1 & 0 & 1 & 0 & & & & 1010<11001 \
& & & & & & & & - & 0 & 0 & 0 & 0 & 0 & & & & \gets 0{\cdot}11001 \
\cline{10-15} & & & & & & & & & & 1 & 0 & 1 & 0 & 0 & & & 10100<11001 \
& & & & & & & & - & & 0 & 0 & 0 & 0 & 0 & & & \gets 01{\cdot}11001 \
\cline{11-16} & & & & & & & & & & 1 & 0 & 1 & 0 & 0 & 0 & & 101000>11001 \
& & & & & & & & & & - & 1 & 1 & 0 & 0 & 1 & & \gets 1{\cdot}11001 \
\cline{12-17} & & & & & & & & & & & 0 & 1 & 1 & 1 & 1 & 0 & 111101>11001 \
& & & & & & & & & & & - & 1 & 1 & 0 & 0 & 1 & \gets 0{\cdot}11001 \
\cline{12-17} & & & & & & & & & & & & 0 & 0 & 1 & 0 & 1 & \text{FCS}
\end{tblr}

%---------------------------------------------------------------% \begin{tblr}{colspec={*{17}{Q[c,mode=math]} Q[r, fg=black!70, font=\tiny, mode=math, leftsep=6pt] }, cell{odd[2-Z]}{18} = {l}, } & & & & & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & \
1 & 1 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 1 & 1<11001 \ & & & & - & 0 & & & & & & & & & & & & \gets 0{\cdot}11001 \
\cline{6-7} & & & & & 1 & 1 & & & & & & & & & & & 11<11001 \ & & & & - & 0 & 0 & & & & & & & & & & & \gets 0{\cdot}11001 \
\cline{6-8} & & & & & 1 & 1 & 1 & & & & & & & & & & 111<11001 \
& & & & & - & 0 & 0 & & & & & & & & & & \gets 0{\cdot}11001 \ \cline{6-9} & & & & & 1 & 1 & 1 & 0 & & & & & & & & & 1110<11001 \
& & & & - & 0 & 0 & 0 & 0 & & & & & & & & & \gets 0{\cdot}11001 \
\cline{6-10} & & & & & 1 & 1 & 1 & 0 & 0 & & & & & & & & 11100>11001 \
& & & & - & 1 & 1 & 0 & 0 & 1 & & & & & & & & \gets 1{\cdot}11001 \
\cline{6-11} & & & & & 0 & 0 & 0 & 1 & 1 & 1 & & & & & & & 111<11001 \
& & & & & - & 0 & 0 & 0 & 0 & 0 & & & & & & & \gets 0{\cdot}11001 \
\cline{6-12} & & & & & & 0 & 0 & 1 & 1 & 1 & 1 & & & & & & 1110<11001 \
& & & & & & - & 0 & 0 & 0 & 0 & 0 & & & & & & \gets 0{\cdot}11001 \ \cline{8-13} & & & & & & & 0 & 1 & 1 & 1 & 1 & 0 & & & & & 11110>11001 \
& & & & & & & - & 1 & 1 & 0 & 0 & 1 & & & & & \gets 1{\cdot}11001 \
\cline[fg=red]{9-14} & & & & & & & & 0 & 0 & 1 & 0 & 1 & 0 & & & & 1011<11001 \
& & & & & & & & - & 0 & 0 & 0 & 0 & 0 & & & & \gets 0{\cdot}11001 \
\cline{10-15} & & & & & & & & & & 1 & 0 & 1 & 0 & 1 & & & 101010<11001 \
& & & & & & & & - & & 0 & 0 & 0 & 0 & 0 & & & \gets 01{\cdot}11001 \
\cline{11-16} & & & & & & & & & & 1 & 0 & 1 & 0 & 1 & 0 & & 101101>11001 \
& & & & & & & & & & - & 1 & 1 & 0 & 0 & 1 & & \gets 1{\cdot}11001 \
\cline{12-17} & & & & & & & & & & & 1 & 0 & 1 & 0 & 0 & 1 & 111101>11001 \
& & & & & & & & & & & - & 1 & 1 & 0 & 0 & 1 & \gets 1{\cdot}11001 \
\cline{12-17} & & & & & & & & & & & & 0 & 0 & 0 & 0 & 0 & \text{ni napake}
\end{tblr} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{document}

which gives the following result:

enter image description here

BTW, after finishing above code and compare results with showed example, I observe, that it has errors :-(.

Anyway, I hope that above code will be of help to someone.

Zarko
  • 296,517
0

Have a look on https://www.ctan.org/pkg/basicarith which provides the formatting macros without carrying out the the computation automatically, and consider write a program to generate the binary division sequences.

LdBeth
  • 708
  • Thank you for info. After short check of this package I don't see if it support binary calculation, i.e. 1110 + 1100 = 0010. Please correct me (if possible with some example) that I'm wrong. – Zarko Mar 10 '24 at 00:21
  • @Zarko No, it does not carry out binary computation. – LdBeth Mar 10 '24 at 00:25