Debian Codegraph @

docsrc/xlisp/xlisp-doc/examples/octal.htm

raw symbols SCIP
1 <html><head>
2
3 <title>Octal Integer Numbers</title>
4
5 <style type="text/css">
6 .example {
7 color: #000000;
8 background-color: #F5F5F5;
9 padding: 8px;
10 border: #808080;
11 border-style: solid;
12 border-width: 1px;
13 width:auto;
14 }
15 .button {
16 color: #000000;
17 background-color: #F5F5F5;
18 padding-top: 1px;
19 padding-bottom: 1px;
20 padding-left: 4px;
21 padding-right: 8px;
22 border: #808080;
23 border-style: solid;
24 border-width: 1px;
25 white-space: pre;
26 }
27 .box {
28 color: #000000;
29 padding-top: 4px;
30 padding-bottom: 4px;
31 padding-left: 16px;
32 padding-right: 16px;
33 border: #808080;
34 border-style: solid;
35 border-width: 1px;
36 }
37 </style>
38
39 </head>
40
41 <body>
42
43 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
44 <a href="../manual/contents.htm">Contents</a> |
45 <a href="../tutorials/tutorials.htm">Tutorials</a> |
46 <a href="examples.htm">Examples</a> |
47 <a href="../reference/reference-index.htm">Reference</a>
48
49 <hr>
50
51 <h1>Octal Integer Numbers</h1>
52
53 <hr>
54
55 <p>XLISP provides the <a href="../manual/xlisp.htm#octal">#o</a>
56 <nobr>read-macro</nobr> for octal numbers:</p>
57
58 <pre class="example">
59 #o0 =&gt; 0 #o10 =&gt; 8 #o20 =&gt; 16
60 #o1 =&gt; 1 #o11 =&gt; 9 #o21 =&gt; 17
61 #o2 =&gt; 2 #o12 =&gt; 10 #o22 =&gt; 18
62 #o3 =&gt; 3 #o13 =&gt; 11 #o23 =&gt; 19
63 #o4 =&gt; 4 #o14 =&gt; 12 #o24 =&gt; 20
64 #o5 =&gt; 5 #o15 =&gt; 13 #o25 =&gt; 21
65 #o6 =&gt; 6 #o16 =&gt; 14 #o26 =&gt; 22
66 #o7 =&gt; 7 #o17 =&gt; 15 #o27 =&gt; 23
67 </pre>
68
69 <p><div class="box">
70
71 <dl>
72 <dt>(<b>oct-string</b> <i>integer</i> [<i>all</i>])</dt>
73 <dd><i>integer</i> - an integer expression<br>
74 <i>all</i> - a boolean expression<br>
75 returns - the <i>integer</i> in octal form as string</dd>
76 </dl>
77
78 </div></p>
79
80 <pre class="example">
81 (defun <font color="#0000CC">oct-string</font> (integer &amp;optional all)
82 (if (integerp integer)
83 (let ((fmt (if all
84 (or (dolist (bits '(16 32 64 128) nil)
85 (let ((fixnum (round (expt 2.0 (1- bits)))))
86 (and (plusp (1- fixnum))
87 (minusp fixnum)
88 (return (format nil <font color="#880000">"%.~ao"</font>
89 (1+ (/ bits 3)))))))
90 (error <font color="#880000">"integer limit not found"</font>))
91 <font color="#880000">"%o"</font>)))
92 (progv '(<font color="#AA5500">*integer-format*</font>) (list fmt)
93 (format nil <font color="#880000">"~a"</font> integer)))
94 (error <font color="#880000">"not an integer"</font> integer)))
95 </pre>
96
97 <p>The '<nobr>oct-string</nobr>' function converts the 'integer' argument
98 into octal form and returns is as a string. <nobr>If the</nobr>
99 optional 'all' argument is not given or
100 <a href="../reference/nil.htm">NIL</a>, leading zeros are not included in
101 the string. <nobr>If the</nobr> optional 'all' argument is
102 <nobr>non-<a href="../reference/nil.htm">NIL</a></nobr>, all digits of the
103 internal representation of the 'integer' argument, including leading zeros,
104 are contained in the string. This is useful for debugging integer overflow
105 and <nobr>bit-wise</nobr> functions.</p>
106
107 <p><div class="box">
108
109 <dl>
110 <dt>(<b>oct</b> <i>integer</i> [<i>all</i>])</dt>
111 <dd><i>integer</i> - an integer expression<br>
112 <i>all</i> - a boolean expression<br>
113 prints - the <i>integer</i> in octal form<br>
114 returns - the <i>integer</i> argument</dd>
115 </dl>
116
117 </div></p>
118
119 <pre class="example">
120 (defun <font color="#0000CC">oct</font> (integer &amp;optional all)
121 (if (integerp integer)
122 (format t <font color="#880000">"#o~a~%"</font> (oct-string integer all))
123 (format t <font color="#880000">";; not an integer~%"</font>))
124 integer)
125 </pre>
126
127 <p>The 'oct' function prints the 'integer' argument in octal form on
128 the screen. Together with the
129 <a href="../manual/xlisp.htm#octal">#o</a> <nobr>read-macro</nobr>
130 this can be used for interactive octal computations.</p>
131
132 <pre class="example">
133 &gt; (oct 12345678)
134 #o57060516
135 12345678
136 </pre>
137
138 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
139
140 <hr>
141
142 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
143 <a href="../manual/contents.htm">Contents</a> |
144 <a href="../tutorials/tutorials.htm">Tutorials</a> |
145 <a href="examples.htm">Examples</a> |
146 <a href="../reference/reference-index.htm">Reference</a>
147
148 </body></html>