summaryrefslogtreecommitdiff
path: root/docsrc/xlisp/xlisp-doc/examples/xlisp/ash.htm
diff options
context:
space:
mode:
Diffstat (limited to 'docsrc/xlisp/xlisp-doc/examples/xlisp/ash.htm')
-rw-r--r--docsrc/xlisp/xlisp-doc/examples/xlisp/ash.htm130
1 files changed, 130 insertions, 0 deletions
diff --git a/docsrc/xlisp/xlisp-doc/examples/xlisp/ash.htm b/docsrc/xlisp/xlisp-doc/examples/xlisp/ash.htm
new file mode 100644
index 0000000..2d17d98
--- /dev/null
+++ b/docsrc/xlisp/xlisp-doc/examples/xlisp/ash.htm
@@ -0,0 +1,130 @@
+<html><head>
+
+<title>ash</title>
+
+<style type="text/css">
+.example {
+ color: #000000;
+ background-color: #F5F5F5;
+ padding: 8px;
+ border: #808080;
+ border-style: solid;
+ border-width: 1px;
+ width:auto;
+}
+.button {
+ color: #000000;
+ background-color: #F5F5F5;
+ padding-top: 1px;
+ padding-bottom: 1px;
+ padding-left: 4px;
+ padding-right: 8px;
+ border: #808080;
+ border-style: solid;
+ border-width: 1px;
+ white-space: pre;
+}
+.box {
+ color: #000000;
+ padding-top: 4px;
+ padding-bottom: 4px;
+ padding-left: 16px;
+ padding-right: 16px;
+ border: #808080;
+ border-style: solid;
+ border-width: 1px;
+}
+</style>
+
+</head>
+
+<body>
+
+<a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
+<a href="../../manual/contents.htm">Contents</a> |
+<a href="../../tutorials/tutorials.htm">Tutorials</a> |
+<a href="../examples.htm">Examples</a> |
+<a href="../../reference/reference-index.htm">Reference</a>
+
+<hr>
+
+<h1>ash</h1>
+
+<hr>
+
+<p>The 'ash' functio performs an '<nobr>arithmetic shift</nobr>' operation:</p>
+
+<p><div class="box">
+
+<dl>
+<dt>(<b>ash</b> <i>integer count</i>)</dt>
+<dd><i>integer</i> - an integer expression<br>
+<i>count</i> - an integer expression<br>
+returns - the <i>number</i> shifted by <i>count</i></dd>
+</dl>
+
+</div></p>
+
+<pre class="example">
+(defun <font color="#0000CC">ash</font> (integer count)
+ (or (integerp integer) (error <font color="#880000">"not an integer"</font> integer))
+ (or (integerp count) (error <font color="#880000">"not an integer"</font> count))
+ (let* ((shift (* integer (expt 2.0 count)))
+ (trunc (truncate shift)))
+ <font color="#008844">;; XLISP implementation of (FLOOR SHIFT)</font>
+ (if (or (plusp shift) (= shift trunc))
+ trunc
+ (1- trunc))))
+</pre>
+
+<p>The 'ash' functio performs an arithmetic shift operation on the binary
+representation of the 'integer' argument, which is treated as if it were
+binary. <nobr>The 'integer'</nobr> argument is shifted arithmetically to the
+left by 'count' bit positions if 'count' is positive, or to the right by
+'count' bit positions if 'count' is negative. <nobr>The shifted</nobr> value
+of the same sign as 'integer' is returned.</p>
+
+<p>The 'ash' function performs the computation:</p>
+
+<pre class="example">
+floor (integer * 2^count)
+</pre>
+
+<p>Logically, the 'ash' function moves all of the bits in integer to the
+left, adding <nobr>zero-bits</nobr> at the right, or moves them to the
+right, discarding bits.</p>
+
+<p>The 'ash' function is defined to behave as if integer were represented in
+two's complement form, regardless of how integers are represented
+internally.</p>
+
+<p>Examples:</p>
+
+<pre class="example">
+(ash 16 1) =&gt; 32
+(ash 16 0) =&gt; 16
+(ash 16 -1) =&gt; 8
+</pre>
+
+<pre class="example">
+(defun <font color="#0000CC">debug:ash</font> (integer count)
+ (let ((shifted (ash integer count)))
+ (format t <font color="#880000">"integer: ~a~%"</font> (bin-string integer :all))
+ (format t <font color="#880000">"shifted: ~a~%"</font> (bin-string shifted :all))
+ shifted))
+</pre>
+
+<p>See <nobr><a href="../binary.htm">Binary Integer Numbers</a></nobr> for
+the '<nobr>bin-string</nobr>' function.</p>
+
+<p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
+
+<hr>
+
+<a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
+<a href="../../manual/contents.htm">Contents</a> |
+<a href="../../tutorials/tutorials.htm">Tutorials</a> |
+<a href="../examples.htm">Examples</a> |
+<a href="../../reference/reference-index.htm">Reference</a>
+
+</body></html>