You are looking at historical revision 38589 of this page. It may differ significantly from its current revision.
bitwise-utils
Documentation
Additional bitwise routines.
bitwise-mask
[procedure] (bitwise-mask WID [ON?]) --> integerReturns WID low-order bits ON?.
- WID
- fixnum ; mask bit width.
- ON?]
- boolean ; #t is #b1, #f is #b0; default #t.
(bitwise-mask 5 #t) ;=> +0...011111 (#b+011111) (bitwise-mask 5 #f) ;=> -1...100000 (#b-100000)
bitwise-join
[procedure] (bitwise-join N0 [N1 ...]) --> integerReturns adjoined bits.
- N0
- integer ; seed.
- N1 ...
- integer ... ; adjoins seed left-to-right.
(bitwise-join #b10 #b0000001 #b101) ;=> #b101101
bitwise-split
[procedure] (bitwise-split N WID) --> (list-of integer)Returns N disjoined every WID bits.
- N
- integer ; seed.
- WID
- fixnum ; bit width.
(bitwise-split #xabcdef 4) ;=> (#xa #xb #xc #xd #xe #xf) (bitwise-split #x-abcdef 4) ;=> (#x-a #x-b #x-c #x-d #x-e #x-f)
bitwise-count
[procedure] (bitwise-count N) --> fixnumReturns number of set bits in N.
- N
- integer
logical-shift-left
[procedure] (logical-shift-left N1 N2) --> integerReturns left shift of N1 by N2 bits.
- N1
- integer ; what to shift.
- N2
- fixnum ; amount to shift.
Aliases arithmetic-shift.
logical-shift-right
[procedure] (logical-shift-right N1 N2) --> integerReturns right shift of N1 by N2 bits. Sign preserving.
- N1
- integer ; what to shift.
- N2
- fixnum ; amount to shift.
arithmetic-shift-left
[procedure] (arithmetic-shift-left N1 N2) --> integerReturns left shift of N1 by N2 bits.
- N1
- integer ; what to shift.
- N2
- fixnum ; amount to shift.
Aliases arithmetic-shift.
arithmetic-shift-right
[procedure] (arithmetic-shift-right N1 N2) --> integerReturns right shift of N1 by N2 bits. Sign extending.
- N1
- integer ; what to shift.
- N2
- fixnum ; amount to shift.
Essentially (arithmetic-shift <> (- <>)).
Usage
(import bitwise-utils)
Author
Version history
- 1.0.0
- Release.
License
This code is in the public domain.