[erlang-questions] Bit Syntax and compiler Erlang/OTP R21.1
empro2@REDACTED
empro2@REDACTED
Tue Aug 20 18:55:06 CEST 2019
On Tue, 20 Aug 2019 17:04:26 +0200
Valentin Micic <v@REDACTED> wrote:
> (tsdb_1_1@REDACTED)448> is_binary( <<0:1>> ).
>
> false
"is elephant?" is encoded in Erlang as: is_bitstring/1
75> is_bitstring(<<0:1>>).
is_bitstring(<<0:1>>).
true
> But, if you put two elephants next to each other, you get
> — a duck!
>
> is_binary( <<0:5, 0:3>> ).
>
> true
Read "is_binary/1" as
"is_bitstring/1 and (bitlength_of(Elephants) mod 8 == 0)"
:-)
> Given all this, why would anyone find bitstrings useful?
That is why the default bitstring is a bytestring or
octetstring or binary:
98> is_binary(<<"blah">>) and is_binary(<<1, 2, 3>>).
is_binary(<<"blah">>) and is_binary(<<1, 2, 3>>).
true
As long as you do not tell the compiler to take bites of
memory that are no bytes, with that ":", the two of you seem
to agree there.
Might help when extracting flag bits? (or when talking to
some 9-bit byte PDP ... or was that 11? ... ;-) Anyway I
would rather deprecate and obsolete away dot notation for
record elements ...
/Michael
--
Normality is merely a question of quantity,
not of quality.
More information about the erlang-questions
mailing list