Skip to content

Modern Math BitReverse

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Math Library › Math Library › BitReverse

BitReverse

Reverses the order of all the bits in the value's type.

Syntax

BitReverse( byval x as T ) as T

Notes

  • Every bit of the type, not just the significant ones -- so the answer depends on the width and reversing a uint32 1 gives the top bit set.
  • Used by FFTs, by some CRC formulations and by Gray-code addressing.
  • Not ByteSwap: that reorders bytes and leaves each byte's bits alone.

Examples

#import "std/numeric"
using numeric

dim as uint32 x = 1
print hex( BitReverse( x ) ) '' 80000000 -- the bit moved to the top

'' Its own inverse, like ByteSwap
print BitReverse( BitReverse( x ) ) = x       '' -1 (true)

'' And NOT the same operation
print hex( ByteSwap( x ) )   '' 1000000

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally