bits-0.5.1: Various bit twiddling and bitwise serialization primitives

Copyright(c) Edward Kmett 2013-2014
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell98

Data.Bits.Extras

Description

Calculate a number of fiddly bit operations using fast de Bruijn multiplication tables.

Synopsis

Documentation

class (Num t, FiniteBits t) => Ranked t where Source #

Minimal complete definition

nlz

Methods

lsb :: t -> Int Source #

Calculate the least significant set bit using a debruijn multiplication table. NB: The result of this function is undefined when given 0.

rank :: t -> Int Source #

Calculate the number of trailing 0 bits.

nlz :: t -> Int Source #

Calculate the number of leading zeros.

msb :: Ranked t => t -> Int Source #

Calculate the most significant set bit.

w8 :: Integral a => a -> Word8 Source #

w16 :: Integral a => a -> Word16 Source #

w32 :: Integral a => a -> Word32 Source #

w64 :: Integral a => a -> Word64 Source #

assignBit :: Bits b => b -> Int -> Bool -> b Source #

zeroBits :: Bits a => a #

zeroBits is the value with all bits unset.

The following laws ought to hold (for all valid bit indices n):

This method uses clearBit (bit 0) 0 as its default implementation (which ought to be equivalent to zeroBits for types which possess a 0th bit).

Since: 4.7.0.0

oneBits :: Bits b => b Source #

srl :: Bits b => b -> Int -> b Source #

Shift Right Logical (i.e., without sign extension)

NB: When used on negative Integers, hilarity may ensue.