[erlang-questions] map over bitstring
Thu Oct 28 23:23:24 CEST 2010
Seeing binaries contain bytes getting the binary << 292 >> is impossible. You have to put it in more that 8 bits.
----- "rgowka1" <> wrote:
> Hi -
> How can I convert a bitstring that has only characters $1 and $0 into
> a binary.
> <<0,1,0,0,1,0,0,1,0>> to << 2#0100100100 >> to << 292 >>
> something similar to io_lib:fread("~2u",
> but that works on bitstring instead of string.
> On Mon, Oct 25, 2010 at 6:23 AM, Morten Krogh <>
> > Kostis,
> > I followed your suggestion and compiled it to native code with erlc
> > zip2.erl, which improves the runtime for
> > both methods.
> > The run times are, for a 100 MB binary, and the map function X -> X
> + 1 hard
> > coded into the module and into the map method itself (which is not
> > realistic):
> > Not native:
> > comprehension : 10 s
> > my own bit syntax function : 14s
> > native:
> > comprehension: 3.7 s
> > my own bit syntax function: 6 s
> > So, yes native is an improvement!
> > Morten.
> > On 10/25/10 11:30 AM, Kostis Sagonas wrote:
> >> Morten Krogh wrote:
> >>> Sorry, in my recent reply to Tony I tested the comprehension on
> >>> constant ><<"B"">>.
> >>> Putting everything in the module and comparing the same mapped
> >>> ,f , the result is that the comprehension is 30% faster than my
> >>> based map function.
> >> Morten,
> >> You may also want to try compiling the file to native code and
> >> whether or how this improves/changes the results.
> >> Cheers,
> >> Kostis
> > ________________________________________________________________
> > erlang-questions (at) erlang.org mailing list.
> > See http://www.erlang.org/faq.html
> > To unsubscribe; mailto:
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
More information about the erlang-questions