diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-05-14 17:01:55 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-05-14 17:01:55 +0200 |
| commit | a9388ee62cd0553aa62f7305956b37d677d23c97 (patch) | |
| tree | 41026252e6c5a8d1116b7035c2bb480b61a877db | |
| parent | On bit-shifting (diff) | |
| download | libzahl-a9388ee62cd0553aa62f7305956b37d677d23c97.tar.gz libzahl-a9388ee62cd0553aa62f7305956b37d677d23c97.tar.bz2 libzahl-a9388ee62cd0553aa62f7305956b37d677d23c97.tar.xz | |
On bit-truncation
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | doc/bit-operations.tex | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/doc/bit-operations.tex b/doc/bit-operations.tex index 3f2938d..44fc27d 100644 --- a/doc/bit-operations.tex +++ b/doc/bit-operations.tex @@ -88,7 +88,30 @@ whenever possible. One such wrapper could be \section{Truncation} \label{sec:Truncation} -TODO % ztrunc +In \secref{sec:Shift} we have seen how bit-shift +operations can be used to multiply or divide by a +power of two. There is also a bit-truncation +operation: {\tt ztrunc}, which is used to keep +only the lowest bits, or equivalently, calculate +the remainder of a division by a power of two. + +\begin{alltt} + void ztrunc(z_t r, z_t a, size_t b); +\end{alltt} + +\noindent +is consistent with {\tt zmod}; like {\tt zlsh} and +{\tt zrsh}, {\tt a}'s sign is preserved into {\tt r} +assuming the result is non-zero. + +{\tt ztrunc(r, a, b)} stores only the lowest {\tt b} +bits in {\tt a} into {\tt r}, or equivalently, +calculates $r \gets a \mod 2^b$. For example, if + +$a = 100011000_2$ then + +$r = \phantom{10001}1000_2$ after calling +{\tt ztrunc(r, a, 4)}. \newpage |
