1 The package @code{bitwise} provides functions that allow to manipulate
2 bits of integer constants. As always maxima attempts to simplify the result
3 of the operation if the actual value of a constant isn't known considering
4 attributes that might be known for the variables, see the @mref{declare}
8 * Functions and Variables for bitwise::
11 @node Functions and Variables for bitwise, , Top, Top
12 @section Functions and Variables for bitwise
15 @deffn {Function} bit_not (@var{int})
17 Inverts all bits of a signed integer. The result of this action reads
23 @c bit_not(bit_not(i));
29 (%i1) load("bitwise")$
35 (%i3) bit_not(bit_not(i));
52 @opencatbox{Categories:}
53 @category{Number theory}
54 @category{Binary operations}
55 @category{Package bitwise}
60 @deffn {Function} bit_and (@var{int1}, ...)
62 This function calculates a bitwise @code{and} of two or more signed integers.
72 (%i1) load("bitwise")$
91 If it is known if one of the parameters to @code{bit_and} is even this information
92 is taken into consideration by the function.
95 @c declare(e,even,o,odd);
100 (%i1) load("bitwise")$
102 (%i2) declare(e,even,o,odd);
115 @opencatbox{Categories:}
116 @category{Number theory}
117 @category{Binary operations}
118 @category{Package bitwise}
123 @deffn {Function} bit_or (@var{int1}, ...)
125 This function calculates a bitwise @code{or} of two or more signed integers.
135 (%i1) load("bitwise")$
154 If it is known if one of the parameters to @code{bit_or} is even this information
155 is taken into consideration by the function.
158 @c declare(e,even,o,odd);
163 (%i1) load("bitwise")$
165 (%i2) declare(e,even,o,odd);
178 @opencatbox{Categories:}
179 @category{Number theory}
180 @category{Binary operations}
181 @category{Package bitwise}
186 @deffn {Function} bit_xor (@var{int1}, ...)
188 This function calculates a bitwise @code{or} of two or more signed integers.
198 (%i1) load("bitwise")$
204 (%i3) bit_xor(i,i,i);
217 If it is known if one of the parameters to @code{bit_xor} is even this information
218 is taken into consideration by the function.
221 @c declare(e,even,o,odd);
226 (%i1) load("bitwise")$
228 (%i2) declare(e,even,o,odd);
241 @opencatbox{Categories:}
242 @category{Number theory}
243 @category{Binary operations}
244 @category{Package bitwise}
250 @deffn {Function} bit_lsh (@var{int}, @var{nBits})
252 This function shifts all bits of the signed integer @code{int} to the left by
253 @code{nBits} bits. The width of the integer is extended by @code{nBits} for
254 this process. The result of @code{bit_lsh} therefore is @code{int * 2}.
266 (%i1) load("bitwise")$
292 @opencatbox{Categories:}
293 @category{Number theory}
294 @category{Binary operations}
295 @category{Package bitwise}
301 @deffn {Function} bit_rsh (@var{int}, @var{nBits})
303 This function shifts all bits of the signed integer @code{int} to the right by
304 @code{nBits} bits. The width of the integer is reduced by @code{nBits} for
318 (%i1) load("bitwise")$
348 @opencatbox{Categories:}
349 @category{Number theory}
350 @category{Binary operations}
351 @category{Package bitwise}
356 @deffn {Function} bit_length (@var{int})
358 determines how many bits a variable needs to be long in order to store the
359 number @code{int}. This function only operates on positive numbers.
369 (%i1) load("bitwise")$
387 @opencatbox{Categories:}
388 @category{Number theory}
389 @category{Binary operations}
390 @category{Package bitwise}
395 @deffn {Function} bit_onep (@var{int}, @var{nBit})
397 determines if bits @code{nBit} is set in the signed integer @code{int}.
409 (%i1) load("bitwise")$
411 (%i2) bit_onep(85,0);
415 (%i3) bit_onep(85,1);
419 (%i4) bit_onep(85,2);
423 (%i5) bit_onep(85,3);
427 (%i6) bit_onep(85,100);
431 (%i7) bit_onep(i,100);
432 (%o7) bit_onep(i, 100)
436 For signed numbers the sign bit is interpreted to be more than @code{nBit} to the
437 left of the leftmost bit of @code{int} that reads @code{1}.
447 (%i1) load("bitwise")$
449 (%i2) bit_onep(-2,0);
453 (%i3) bit_onep(-2,1);
457 (%i4) bit_onep(-2,2);
461 (%i5) bit_onep(-2,3);
465 (%i6) bit_onep(-2,4);
471 If it is known if the number to be tested is even this information
472 is taken into consideration by the function.
475 @c declare(e,even,o,odd);
480 (%i1) load("bitwise")$
482 (%i2) declare(e,even,o,odd);
495 @opencatbox{Categories:}
496 @category{Number theory}
497 @category{Binary operations}
498 @category{Package bitwise}