bitwise-reverse-bit-field, fxreverse-bit-field - reverse bit order in an integer

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs arithmetic bitwise))  ;R6RS
(import (rnrs arithmetic fixnums))  ;R6RS

SYNOPSIS

(bitwise-reverse-bit-field n start end)
(fxreverse-bit-field n start end)

DESCRIPTION

Returns the integer obtained by by reversing the order of the bits in n at positions from start (inclusive) to end (exclusive).

RETURN VALUES

Returns a single value; an integer.

EXAMPLES


(bitwise-reverse-bit-field #b0011 0 4)
                           ;   ||
                           ;   vv
                           => #b1100

(bitwise-reverse-bit-field #xAA 0 8)
        => #x55

(bitwise-reverse-bit-field #xAABBCCDD 24 32)
        => #x55BBCCDD

APPLICATION USAGE

These procedures commonly show up when implementing algorithms from coding theory.

RATIONALE

A native implementation of these procedures can be made much faster than one provided by the user.

COMPATIBILITY

These procedures are new in R6RS. There is a similar procedure in SRFI-151.

ERRORS

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain. In particular, start and end must be non-negative, and start must be less than or equal to end.

For the fixnum variant, in addition to the above, the arguments must be fixnums, and end must be less than the fixnum width. See fixnum-width(3scm).

SEE ALSO

bitwise-rotate-bit-field(3scm), bitwise-arithmetic-shift(3scm), bitwise-copy-bit-field(3scm)

STANDARDS

R6RS

HISTORY

First appeared in R6RS.

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.

BUGS

Programs should be careful to limit the end argument of the generic procedure to a reasonable value to prevent excessive resource usage.


Markup created by unroff 1.0sc,    March 04, 2023.