chickadee » bitwise-utils

bitwise-utils

Documentation

Additional bitwise routines.

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

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 <> (- <>)).

Usage

(import bitwise-utils)

Author

Kon Lovett

Version history

1.0.0
Release.

License

This code is in the public domain.

Contents »