[erlang-questions] Re. How to decode octet to septets using erlang (prasantha kumara)

Tony Seebregts <>
Thu Mar 5 13:36:06 CET 2009


Hmmm , the short answer is that the code I suggested is taken from a module
to convert a GSM octet stream into a septet stream and it gives a different
answer when using your more compact code :-) :
UD:      << 203,176,184,204,86,191,1 >>
Mine:    [75,97,98,101,108,106,111,0]
Yours:  << 101,108,23,12,98,90,126,1>>

I remember the GSM octet-septet conversion being quite awkward to get right
because the bytes were the 'wrong way round'  which is probably why I ended
up with the code I did i.e. having to use flip(...).


2009/3/5 Hynek Vychodil <>

> Why not?
>
> unpack(UD) ->
>   << <<0:1,X/bits>> || <<X:7/bits>> <= UD >>.
>
> 2009/3/5 Tony Seebregts <>
>
>> This is an extract from the code I use:
>>
>>> unpack(UD) ->
>>>    septets(list_to_binary([ flip(X) || X <- binary_to_list(UD) ])).
>>>
>>> septets(T) ->
>>>     [ flipx(X) || <<X:7>> <= T].
>>>
>>> % Flips the bits in an octet/septet for easy unpacking
>>>
>>> flip(Octet) ->
>>>    <<B8:1,B7:1,B6:1,B5:1,B4:1,B3:1,B2:1,B1:1>>  = <<Octet>>,
>>>    <<B1:1,B2:1,B3:1,B4:1,B5:1,B6:1,B7:1,B8:1>>.
>>>
>>
>> There is probably a better way of doing it but I was in a rush at the time
>> :-)
>>
>>
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>
>
>
> --
> --Hynek (Pichi) Vychodil
>
> Analyze your data in minutes. Share your insights instantly. Thrill your
> boss.  Be a data hero!
> Try Good Data now for free: www.gooddata.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090305/ee827dc3/attachment.html>


More information about the erlang-questions mailing list