chickadee » bitwise-utils

bitwise-utils

Documentation

Additional bitwise routines.

Usage

(import bitwise-utils)

logical-shift-left

logical-shift-left N1 N2procedure

Returns left shift of N1 by N2 bits.

N1
integer ; what to shift.
N2
fixnum ; amount to shift.

Aliases arithmetic-shift.

logical-shift-right

logical-shift-right N1 N2procedure

Returns right shift of N1 by N2 bits. Sign preserving.

N1
integer ; what to shift.
N2
fixnum ; amount to shift.

arithmetic-shift-left

arithmetic-shift-left N1 N2procedure

Returns left shift of N1 by N2 bits.

N1
integer ; what to shift.
N2
fixnum ; amount to shift.

Aliases arithmetic-shift.

arithmetic-shift-right

arithmetic-shift-right N1 N2procedure

Returns right shift of N1 by N2 bits. Sign extending.

N1
integer ; what to shift.
N2
fixnum ; amount to shift.

Essentially (arithmetic-shift <> (- <>)).

bitwise-mask

bitwise-mask WID #!optional ON?procedure

Returns 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

(bitwise-join N0 [N1 ...]) -> integerprocedure

Returns adjoined bits.

N0
integer ; seed.
N1 ...
integer ... ; adjoins seed left-to-right.
(bitwise-join #b10 #b0000001 #b101) ;=> #b101101

bitwise-split

bitwise-split N WIDprocedure

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

bitwise-count Nprocedure

Returns number of set bits in N.

N
integer

bitwise-merge

bitwise-merge MASK N0 N1procedure
MASK
integer
N0
integer
N1
integer

Renamed SRFI-60 bitwise-if.

bitwise-nth?

bitwise-nth? INDEX Nprocedure
INDEX
integer
N
fixnum

Renamed SRFI-60 bit-set?.

bitwise-any?

bitwise-any? N1 N2procedure
N1
integer
N2
integer

Renamed SRFI-60 any-bits-set?.

bitwise-first-set

bitwise-first-set Nprocedure
N
integer

Renamed SRFI-60 first-set-bit.

bitwise-reverse

bitwise-reverse N Kprocedure
N
integer
K
fixnum

bitwise-rotate

bitwise-rotate K COUNT LENprocedure

Performs (bitwise-field-rotate K COUNT 0 LEN).

K
integer
COUNT
fixnum
LEN
fixnum

bitwise-set-nth

bitwise-set-nth TO INDEX ON?procedure
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

bitwise-field N START ENDprocedure
N
integer
START
fixnum
END
fixnum

Renamed SRFI-60 bit-field.

bitwise-field-copy

bitwise-field-copy TO FROM START ENDprocedure
TO
integer
FROM
integer
START
fixnum
END
fixnum

Renamed SRFI-60 copy-bit-field.

bitwise-field-reverse

bitwise-field-reverse N START ENDprocedure
N
integer
START
fixnum
END
fixnum

Renamed SRFI-60 reverse-bit-field.

bitwise-field-rotate N COUNT START ENDprocedure
N
integer
COUNT
fixnum
START
fixnum
END
fixnum

Renamed SRFI-60 rotate-bit-field.

number->boolean

number->boolean NUMprocedure

0 => #f & {{¬ 0}} => #t.

boolean->number

boolean->number ANYprocedure

#f => 0 & #t => 1.

integer->list

integer->list K #!optional LENprocedure
K
integer ; integer to represent as a bit list.
LEN
fixnum ; number of bits, default is all bits.

list->integer

list->integer BOOLSprocedure
BOOLS
list ; treated as (list-of boolean-like)

bitwise-zeros

bitwise-zeros Nprocedure

Return N zero bits.

N
fixnum

bitwise-ones

bitwise-ones Nprocedure

Return N one bits.

N
fixnum

bitwise-abs

bitwise-abs Nprocedure

Should N be negative bitwise-not the result.

N
integer

bitwise-drop-right

bitwise-drop-right N Wprocedure

Drop W right bits of N.

N
integer
W
fixnum

bitwise-cons

bitwise-cons N Mprocedure

Concatenate N & M.

N
integer
M
integer

Requirements

test test-utils

Author

Kon Lovett

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.

Contents »