[erlang-questions] Bitstring question
Karolis Petrauskas
<>
Wed Feb 12 08:16:58 CET 2014
Bitstring concatenation would work, if both parts would be bitstrings,
e.g. A = <<1:4>>, B = <<0:4>>, C = <<A/bits, B/bits>>. In your case
you tried to concatenate an integer with a bitstring. Nice description
of bit syntax can be found in LYSE
(http://learnyousomeerlang.com/starting-out-for-real#bit-syntax). I
hope it helped :)
Karolis
On Wed, Feb 12, 2014 at 9:09 AM, Mike Oxford <> wrote:
> interesting. So why doesn't bitstring concatenation work in this case?
> Should it?
>
>
> On Tue, Feb 11, 2014 at 11:05 PM, Karolis Petrauskas
> <> wrote:
>>
>> The "/bits" says, that the argument is bitstring.
>> The "0:2" says, its an integer who's size is 2 bits. And "0" here is
>> an integer, not a bitstring.
>>
>> Karolis
>>
>> On Wed, Feb 12, 2014 at 9:01 AM, Mike Oxford <> wrote:
>> > Thank you!
>> > But ...
>> >
>> > 64> <<0:2/bits, D/bits>>.
>> > ** exception error: bad argument
>> > 65> <<0:2, D/bits>>.
>> > <<"!">>
>> >
>> > ?? Why does explicitly qualifying the 0:2 with /bits cause it to fail?
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Tue, Feb 11, 2014 at 10:41 PM, Karolis Petrauskas
>> > <> wrote:
>> >>
>> >> 1> D = <<33:6>>.
>> >> <<33:6>>
>> >> 3> E = <<0:2, D/bits>>.
>> >> <<"!">>
>> >> 5> <<F>> = E.
>> >> <<"!">>
>> >> 6> F.
>> >> 33
>> >>
>> >> Karolis
>> >>
>> >> On Wed, Feb 12, 2014 at 8:36 AM, Mike Oxford <> wrote:
>> >> > << 0:2, D >> should concat the two. Erlang knows what D is.
>> >> > <<0:2/bits, D:6/bits>> should construct a single 8-bit value.
>> >> > <<D/integer>> should (IMO) be valid because the value (33) is within
>> >> > the
>> >> > range of /integer
>> >> >
>> >> > How would you convert it back out to 33?
>> >> >
>> >> >
>> >> > On Tue, Feb 11, 2014 at 10:32 PM, Dmitry Kolesnikov
>> >> > <>
>> >> > wrote:
>> >> >>
>> >> >> Hello,
>> >> >>
>> >> >> Please see comments inline.
>> >> >>
>> >> >> Best Regards,
>> >> >> Dmitry >-|-|-(*>
>> >> >>
>> >> >>
>> >> >> > On 12.2.2014, at 8.27, Mike Oxford <> wrote:
>> >> >> >
>> >> >> > D = <<33:6>>
>> >> >> > <<33:6>>
>> >> >> D is length 6 bit
>> >> >> >
>> >> >> > I want to convert that 6 bit value (33) into a numeric value.
>> >> >> >
>> >> >> > Why does <<0:2, D>> not work?
>> >> >> Type and size is not specified
>> >> >> > Why does <<0:2/bits, D:6/bits>> not work?
>> >> >> Expected size is 8 bits but your bit string is 6
>> >> >> > Why does <<D/integer>> not work?
>> >> >> Integer is 32bit
>> >> >>
>> >> >> >
>> >> >> > Thanks in advance!
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > _______________________________________________
>> >> >> > erlang-questions mailing list
>> >> >> >
>> >> >> > http://erlang.org/mailman/listinfo/erlang-questions
>> >> >
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > erlang-questions mailing list
>> >> >
>> >> > http://erlang.org/mailman/listinfo/erlang-questions
>> >> >
>> >
>> >
>
>
More information about the erlang-questions
mailing list