[erlang-questions] checksum calculation
jm
jeffm@REDACTED
Mon Apr 6 01:05:44 CEST 2009
Is this what you had in mind? (NB: typed directly into email and is
unchecked).
checksum(B) when is_binary(B) ->
checksum(B, 0).
checksum(<<>>, Csum) -> %% this is the terminating case
Csum;
checksum(<<N, Rest>>, Csum) -> %% this is the general cas eyou already had
checksum(Rest, Csum bxor N).
Hope that helps.
Jeff.
Gamoto wrote:
> I have a string of bytes and would like to compute the checksum which is the xor of all bytes.
>
> Let S the string, N the current byte
>
> checksum( <<N,Rest>>,Csum) ->
> checksum(Rest,Csum bxor N);
>
> The problems are: I don't know how to start (checksum(<<S>>) ???) and how to finish !
> First of all, is it the correct approach ?
> (I suppose I rather should make Csum Exclusive-OR N modulo 8 ???)
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list