bitwise-utils
- bitwise-utils
- Documentation
- Usage
- logical-shift-left
- logical-shift-right
- arithmetic-shift-left
- arithmetic-shift-right
- bitwise-mask
- bitwise-join
- bitwise-split
- bitwise-count
- bitwise-merge
- bitwise-nth?
- bitwise-any?
- bitwise-first-set
- bitwise-reverse
- bitwise-rotate
- bitwise-set-nth
- bitwise-field
- bitwise-field-copy
- bitwise-field-reverse
- number->boolean
- boolean->number
- integer->list
- list->integer
- bitwise-zeros
- bitwise-ones
- bitwise-abs
- bitwise-drop-right
- bitwise-cons
- Requirements
- Author
- Repository
- Version history
- License
Documentation
Additional bitwise routines.
Usage
(import bitwise-utils)
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 <> (- <>)).
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
bitwise-merge
[procedure] (bitwise-merge MASK N0 N1) -> integer- MASK
- integer
- N0
- integer
- N1
- integer
Renamed SRFI-60 bitwise-if.
bitwise-nth?
[procedure] (bitwise-nth? INDEX N) -> boolean- INDEX
- integer
- N
- fixnum
Renamed SRFI-60 bit-set?.
bitwise-any?
[procedure] (bitwise-any? N1 N2) -> boolean- N1
- integer
- N2
- integer
Renamed SRFI-60 any-bits-set?.
bitwise-first-set
[procedure] (bitwise-first-set N) -> fixnum- N
- integer
Renamed SRFI-60 first-set-bit.
bitwise-reverse
[procedure] (bitwise-reverse N K) -> integer- N
- integer
- K
- fixnum
bitwise-rotate
[procedure] (bitwise-rotate K COUNT LEN) -> integerPerforms (bitwise-field-rotate K COUNT 0 LEN).
- K
- integer
- COUNT
- fixnum
- LEN
- fixnum
bitwise-set-nth
[procedure] (bitwise-set-nth TO INDEX ON?) -> integer- TO
- integer
- INDEX
- fixnum
- ON?
- boolean ; #t is #b1, #f is #b0
Renamed SRFI-60 (copy-bit k n b); note argument order change.
bitwise-field
[procedure] (bitwise-field N START END) -> integer- N
- integer
- START
- fixnum
- END
- fixnum
Renamed SRFI-60 bit-field.
bitwise-field-copy
[procedure] (bitwise-field-copy TO FROM START END) -> integer- TO
- integer
- FROM
- integer
- START
- fixnum
- END
- fixnum
Renamed SRFI-60 copy-bit-field.
bitwise-field-reverse
[procedure] (bitwise-field-reverse N START END) -> integer- N
- integer
- START
- fixnum
- END
- fixnum
Renamed SRFI-60 reverse-bit-field.
[procedure] (bitwise-field-rotate N COUNT START END) -> integer- N
- integer
- COUNT
- fixnum
- START
- fixnum
- END
- fixnum
Renamed SRFI-60 rotate-bit-field.
number->boolean
[procedure] (number->boolean NUM) -> boolean0 => #f & ¬ 0 => #t.
boolean->number
[procedure] (boolean->number ANY) -> fixnum#f => 0 & #t => 1.
integer->list
[procedure] (integer->list K [LEN]) -> (list-of boolean)- K
- integer ; integer to represent as a bit list.
- LEN
- fixnum ; number of bits, default is all bits.
list->integer
[procedure] (list->integer BOOLS) -> integer- BOOLS
- list ; treated as (list-of boolean-like)
bitwise-zeros
[procedure] (bitwise-zeros N) -> integerReturn N zero bits.
- N
- fixnum
bitwise-ones
[procedure] (bitwise-ones N) -> integerReturn N one bits.
- N
- fixnum
bitwise-abs
[procedure] (bitwise-abs N) -> integerShould N be negative bitwise-not the result.
- N
- integer
bitwise-drop-right
[procedure] (bitwise-drop-right N W) -> integerDrop W right bits of N.
- N
- integer
- W
- fixnum
bitwise-cons
[procedure] (bitwise-cons N M) -> integerConcatenate N & M.
- N
- integer
- M
- integer
Requirements
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/bitwise-utils
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Version history
- 1.4.1
- Fix list->integer type regression. Fix boolean->number signature.
- 1.4.0
- Add {{}} & {{}}. Fix signatures (clean, not pure).
- 1.3.2
- Slight speed-up.
- 1.3.1
- New test-runner, add tests.
- 1.3.0
- Export useful helpers bitwise-zeros, bitwise-ones, bitwise-abs, bitwise-drop-right, & bitwise-cons.
- 1.2.2
- Fix bitwise->count.
- 1.2.2
- Fix integer->list/list->integer so invertible.
- 1.2.1
- .
- 1.2.0
- Remove srfi-60 module. (Use srfi-60 egg.)
- 1.1.4
- Fix integer->list type.
- 1.1.3
- .
- 1.1.2
- .
- 1.1.1
- .
- 1.1.0
- Add srfi-60 module.
- 1.0.1
- .
- 1.0.0
- Release.
License
This code is in the public domain.