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 #

Minimal complete definition

nlz

Methods

lsb :: t -> Int #

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 #

Calculate the number of trailing 0 bits.

nlz :: t -> Int #

Calculate the number of leading zeros.

Instances

Ranked Int8 # 

Methods

lsb :: Int8 -> Int #

rank :: Int8 -> Int #

nlz :: Int8 -> Int #

Ranked Int16 # 

Methods

lsb :: Int16 -> Int #

rank :: Int16 -> Int #

nlz :: Int16 -> Int #

Ranked Int32 # 

Methods

lsb :: Int32 -> Int #

rank :: Int32 -> Int #

nlz :: Int32 -> Int #

Ranked Int64 # 

Methods

lsb :: Int64 -> Int #

rank :: Int64 -> Int #

nlz :: Int64 -> Int #

Ranked Word8 # 

Methods

lsb :: Word8 -> Int #

rank :: Word8 -> Int #

nlz :: Word8 -> Int #

Ranked Word16 # 

Methods

lsb :: Word16 -> Int #

rank :: Word16 -> Int #

nlz :: Word16 -> Int #

Ranked Word32 # 

Methods

lsb :: Word32 -> Int #

rank :: Word32 -> Int #

nlz :: Word32 -> Int #

Ranked Word64 # 

Methods

lsb :: Word64 -> Int #

rank :: Word64 -> Int #

nlz :: Word64 -> Int #

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

Calculate the most significant set bit.

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

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

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

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

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

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 #

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

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

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