For Gauche 0.9.14Search (procedure/syntax/module):

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

11.14 srfi.60 - Integers as bits

Module: srfi.60

This srfi provides bit operations on integers, regarding them as 2’s complement representation. It is compatible to SLIB’s logical module.

The newer SRFI-151 (see scheme.bitwise - R7RS bitwise operations) provides the same functionality and more, with more consistent naming. We recommend new code to use SRFI-151, while we keep SRFI-60 for the backward compatibility.

The following procedures are Gauche built-in. See Basic bitwise operations, for the description.

lognot           logand           logior           logxor
logtest          logcount         integer-length   logbit?
copy-bit         bit-field        copy-bit-field   ash

The following procedures are defined in SRFI-151. See scheme.bitwise - R7RS bitwise operations, for the description.

bitwise-not      bitwise-and      bitwise-ior      bitwise-xor
arithmetic-shift bit-count        bitwise-if       bit-set?
copy-bit         first-set-bit

We describe procedures that are unique in SRFI-60 below.

Function: bitwise-merge mask n0 n1

[SRFI-60]{srfi.60} Same as bitwise-if (see scheme.bitwise - R7RS bitwise operations).

Function: any-bits-set? mask n

[SRFI-60]{srfi.60} Same as builtin logtest (see Basic bitwise operations). It is also called any-bit-set? in SRFI-151 (see scheme.bitwise - R7RS bitwise operations).

Function: log2-binary-factors n

[SRFI-60]{srfi.60} It is also called as first-set-bit in this srfi, which is also in SRFI-151 (see scheme.bitwise - R7RS bitwise operations). This is equivalent to Gauche’s built-in twos-exponent-factor (see Basic bitwise operations).

Function: rotate-bit-field n count start end

[SRFI-60]{srfi.60} This is equivalent to bit-field-rotate in SRFI-151 (see scheme.bitwise - R7RS bitwise operations).

Function: reverse-bit-field n start end

[SRFI-60]{srfi.60} This is equivalent to bit-field-reverse in SRFI-151 (see scheme.bitwise - R7RS bitwise operations).

Function: integer->list n :optional len

[SRFI-60]{srfi.60} Breaks n to each bits, representing 1 as #t and 0 as #f, LSB last, and returns a list of them. If a nonnegative integer len is given, it specifies the length of the result. If it is omitted, (integer-length n) is used.

(integer->list 10)   ⇒ (#t #f #t #f)
(integer->list 10 6) ⇒ (#f #f #t #f #t #f)

SRFI-151 has similar procedure bits->list, with a reversed bit order (LSB first) (see scheme.bitwise - R7RS bitwise operations).

Function: list->integer lis

[SRFI-60]{srfi.60} Takes a list of boolean values, replaces the true value for 1 and the false value for 0, and compose an integer regarding each value as a binary digit. If n is nonnegative integer, (eqv? (list->integer (integer->list n)) n) is true.

(list->integer '(#f #t #f #t #f)) ⇒ 10

SRFI-151 has similar procedure list->bits, with a reversed bit order (LSB first) (see scheme.bitwise - R7RS bitwise operations).

Function: booleans->integer bool …

[SRFI-60]{srfi.60} ≡ (list->integer (list bool …))

SRFI-151 has similar procedure bits, with a reversed bit order (LSB first) (see scheme.bitwise - R7RS bitwise operations).


Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]


For Gauche 0.9.14Search (procedure/syntax/module):