clash-prelude-0.7.2: CAES Language for Synchronous Hardware - Prelude library

Copyright(C) 2013-2015, University of Twente
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellNone
LanguageHaskell2010
Extensions
  • UndecidableInstances
  • MonoLocalBinds
  • TypeFamilies
  • DataKinds
  • FlexibleContexts
  • MagicHash
  • KindSignatures
  • TypeOperators
  • ExplicitNamespaces

CLaSH.Class.BitPack

Description

 

Synopsis

Documentation

class BitPack a where Source

Convert to and from a BitVector

Associated Types

type BitSize a :: Nat Source

Number of Bits needed to represents elements of type a

Methods

pack :: a -> BitVector (BitSize a) Source

Convert element of type a to a BitVector

>>> pack (-5 :: Signed 6)
111011

unpack :: BitVector (BitSize a) -> a Source

Convert a BitVector to an element of type a

>>> pack (-5 :: Signed 6)
111011
>>> let x = pack (-5 :: Signed 6)
>>> unpack x :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
111011

Instances

bitCoerce :: (BitPack a, BitPack b, BitSize a ~ BitSize b) => a -> b Source

Coerce a value from one type to another through its bit representation.

>>> pack (-5 :: Signed 6)
111011
>>> bitCoerce (-5 :: Signed 6) :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
111011