[erlang-questions] erlang's binary representation of 7 compared to other languages

Robert Virding <>
Fri Jul 30 04:29:46 CEST 2010


The reason why Erlang doesn't specially recognise \a as 7 is that when
we added character escaping we tool the basic C set and used that.
IIRC \a wasn't in that set. To do it now would be to introduce
something which in not backwards compatible so not without its
problems. Although I think very few would be affected by it. Btw the 7
is BEL in the ascii characters, unfortunately \b is already taken.

Robert

On 30 July 2010 03:51, Woody Peterson <> wrote:
> Thanks for the quick reply! So you're saying erlang can't be made to
> recognize "\a"; any idea why "\07" and "\a" are considered equivalent, but
> the two languages chose incompatible representations? Or, if erlang can't
> parse "\a" (I was hoping for an option a la
> http://www.erlang.org/doc/programming_examples/bit_syntax.html#id2261157), I
> guess the simplest answer is how to get ruby to output "\07", which isn't on
> topic here.
>
> I'm always down for a quick fix, so I'll see if any rubyists know how to
> accomplish the latter, but I'm going to lose sleep if I don't know why the
> opposing designs exist in the first place :)
>
> On Jul 29, 2010, at 6:36 PM, Michael Truog wrote:
>
>> I think this is just because Erlang does not recognize the "\a" encoding
>> and instead just recognizes "a" ("\07" seems best in this case, and is
>> equivalent to "\a"):
>> 4> <<"\n">>.
>> <<"\n">>
>> 5> <<"\a">>.
>> <<"a">>
>> 6> <<"\07">>.
>> <<7>>
>> 7>
>>
>> - Michael
>>
>> On 07/29/2010 06:19 PM, Woody Peterson wrote:
>>>
>>> I have a problem that's on the borders of ruby and erlang, and I
>>> figured the erlang list would generally be more familiar with binary
>>> issues. And forgive me for my haziness with the terminology here...
>>>
>>> The basic problem is that ruby encodes the integer 7 as "\a", while
>>> erlang only decodes it as "\007". Ruby *will* decode both "\007" and
>>> "\a" into 7, which makes me think there's more than one opinion about
>>> how it should be encoded.
>>>
>>> The bigger problem is I'm trying to send data from ruby to erlang via
>>> BERT, and turns out it can't handle data (broadly defined) of length 7.
>>>
>>> Here's some code examples:
>>>
>>> ruby:
>>>
>>>   [7].pack("C") # => "\a"
>>>   "\a".unpack("C") # => 7
>>>   "\007".unpack("C") # => 7
>>>
>>> erlang:
>>>
>>>   <<"\a">>. % => <<a>>
>>>   <<"\007">>. % => <<7>>
>>>
>>> That's all I've got. Not sure exactly what to google here, "erlang OR
>>> ruby binary 007" doesn't really get me anywhere (suprise!), plus I'm
>>> not sure what exactly this encoding/decoding specification is called.
>>>
>>> Any help is appreciated, even google terms :p
>>>
>>> -Woody
>>>
>>> ________________________________________________________________
>>> 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 mailing list