[Haskell-cafe] Binary code

Stefan O'Rear stefanor at cox.net
Mon Nov 27 19:42:44 EST 2006

On Mon, Nov 27, 2006 at 06:20:15PM -0600, J. Garrett Morris wrote:
> First, and forgive me if I'm making unwarranted assumptions, but
> http://haskell.org/haskellwiki/Homework_help might be useful.
> On 11/25/06, escafia <escafia at gmail.com> wrote:
> >i've one fuction receiving an int . The objective is return the respective
> >binary code of that int.
> >
> >For example, if i receive 28 the fuction will return 011100.
> >
> >My question is that there is any fuction in libraries that do this?
> >If not, anyone has any suggestion?

It depends on how you plan to represent bit strings.  One of the best
representations of bits strings for computation purposes is packed,
rightmost bit at position 0, pad with 0's.  If you choose that
representation, the function you want is available in the Haskell '98
Prelude.  It's called "id".  I'd recommend using a newtype, however.

More information about the Haskell-Cafe mailing list