From 208ec230e7939d36454ab2a6c969b29d008a17bc Mon Sep 17 00:00:00 2001 From: ch <289995-netravnen@users.noreply.gitlab.com> Date: Mon, 7 Oct 2024 17:14:11 +0200 Subject: [PATCH] Structure: Add macro baseconvertpractice --- structure.tex | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/structure.tex b/structure.tex index cf03c6d..6820e5e 100644 --- a/structure.tex +++ b/structure.tex @@ -277,3 +277,34 @@ % https://tex.stackexchange.com/a/146312 \newlist{mylist}{enumerate*}{1} \setlist[mylist]{label={\alph*)},font={\color{red!25!black}\bfseries}} + + +% https://cscrunch.com/blog/corey-pennycuff/scripting-latex-create-base-conversion-worksheet +\def\colwidth{.42cm} +\newcommand{\baseconvertpractice}[2]{% number, # to not censor (1-3, or 0 for none) + \renewcommand\arraystretch{2} + \FPeval{\num}{#1}% + \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}r|*{8}{>{\centering}p{\colwidth}|}|*{8}{>{\centering}p{\colwidth}|}@{}c@{}} \cline{2-17}% + Decimal & \multicolumn{16}{ r| }{\censorifnotequal{\num}{#2}{1}} &\\ \cline{2-17}% + Binary & \censorifnotequal{\getdigit{\num}{16}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{15}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{14}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{13}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{12}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{11}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{10}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{9}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{8}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{7}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{6}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{5}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{4}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{3}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{2}{2}}{#2}{2} &% + \censorifnotequal{\getdigit{\num}{1}{2}}{#2}{2} &\\ \cline{2-17}% + Hexadecimal & \multicolumn{4}{c|}{\censorifnotequal{\getdigit{\num}{4}{16}}{#2}{3}} &% + \multicolumn{4}{c||}{\censorifnotequal{\getdigit{\num}{3}{16}}{#2}{3}} &% + \multicolumn{4}{c|}{\censorifnotequal{\getdigit{\num}{2}{16}}{#2}{3}} &% + \multicolumn{4}{c|}{\censorifnotequal{\getdigit{\num}{1}{16}}{#2}{3}} &\\ \cline{2-17}% + \end{tabular*}% +}