[erlang-questions] subnet masking with binary matching
Thu Jan 18 07:06:37 CET 2007
Bob Ippolito wrote:
> There's plenty of documentation for all of Erlang's pattern matching
> features in the reference manual.
> You could just do this:
> mask_address(Addr, Maskbits) ->
> B = list_to_binary(tuple_to_list(Addr)),
> io:format("address as binary: ~p ~p~n", [B,Maskbits]),
> Rest = (size(B) * 8) - Maskbits,
> <<Subnet:Maskbits, _Host:Rest>> = B,
> If/when the feature enhancements proposed in that paper end up in
> Erlang, then this code would be shorter and cleaner. It sure would
> make a huge difference in a lot of my code, but even the current
> syntax is much better than bit twiddling other languages.
Found the ref manual after I sent the email. Had the browser open at the
kernel and stdlib only before that.
thanks. that works and help increase my comprehension of the language.
Almost reached for the bit ops. Now I can get back to trying to actually
debug a short module.
More information about the erlang-questions