I think what you need is the round-mode=off
switch. [Addendum, Nov. 2021: see the remark at the bottom of this answer for an explanation on how to get his answer to work if you're working with version 3.x of the siunitx
package.] Here's your MWE, slightly reworked:
\documentclass{scrbook}
\usepackage[round-mode=places, round-integer-to-decimal, round-precision=2,
table-format = 1.2,
table-number-alignment=center,
round-integer-to-decimal,
output-decimal-marker={,}
]{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\sisetup{table-format=1.3, round-precision=3, table-comparator=true, round-integer-to-decimal=false}
\begin{tabular}{S[round-mode=places]S[round-mode=off]}
\toprule
{``Places''} & {``Off''}\\
\midrule
5,2 & 5,2 \\
0,246 & 0,246 \\
<0,002 & <0,002 \\
<0,002 & <0,002 \\
0,007 & 0,007 \\
0,42 & 0,42 \\
6,9 & 6,9 \\
390 & 390 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Addendum, Nov. 2021: In version 3 of the siunitx
package, the valid choices for the round-mode
option are none
, places
, figures
, and uncertainty
. Obseve that off
is no longer a valid choice. Thus, in order to get the code shown above to run under v3 of siunitx
, one needs to replace round-mode=off
with round-mode=none
.
The math functions built into pgf
can be used:
![enter image description here](https://i.stack.imgur.com/vrCoN.png)
Notes:
An integer with prefix 0b
or 0B
is interpreted as a binary number and is automatically converted to base 10. Hence the prefixes in 0b#1 + 0b#2
.
It should be noted that this feature of treating numbers with a leading 0
as an octal number can not be disabled as per
Martin Scharrer's answer at Unexpected results from pgfmath functions with numbers with leading 0.
\pgfmathbin{x}
converts an integer to a binary representation.
\pgfmathprintnumber
is optional and is used to format the number. In this case it automatically detects that the decimal value of the addition is an integer and produces 102
instead of 102.0
as is the case for the first decimal addition.
Code:
\documentclass{article}
\usepackage{pgf}
\newcommand{\BinaryAdd}[2]{%
{#1}_2 + {#2}_2 = \pgfmathbin{0b#1 + 0b#2}% compute binary addition
\pgfmathresult_2% format output to make it clear it is base 2
}%
\newcommand{\BinarySub}[2]{%
{#1}_2 - {#2}_2 = \pgfmathbin{0b#1 - 0b#2}% compute binary subtraction
\pgfmathresult_2% format output to make it clear it is base 2
}%
\newcommand{\DecimalAdd}[2]{%
#1 + #2 = \pgfmathparse{#1 + #2}% compute addition
\pgfmathprintnumber{\pgfmathresult}% format output
}%
\newcommand{\DecimalSub}[2]{%
#1 - #2 = \pgfmathparse{#1 - #2}% compute subtraction
\pgfmathprintnumber{\pgfmathresult}% format output
}%
\begin{document}
$\BinaryAdd{101}{0001}$\par
$\BinarySub{101}{0001}$
\bigskip
$\DecimalAdd{101}{0001}$\par
$\DecimalSub{101}{0001}$
\end{document}
Best Answer
In your initial question I thought you were looking at suggestions for ways of tabulating the bit patterns, something like the first couple of examples. But your edit indicated you wanted to display the working. Something like this might work for that, I just do the easy unsigned case as you showed, I leave the rest as you say it's homework:-)