[erlang-questions] checksum calculation
Mon Apr 6 01:05:44 CEST 2009
Is this what you had in mind? (NB: typed directly into email and is
checksum(B) when is_binary(B) ->
checksum(<<>>, Csum) -> %% this is the terminating case
checksum(<<N, Rest>>, Csum) -> %% this is the general cas eyou already had
checksum(Rest, Csum bxor N).
Hope that helps.
> 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
More information about the erlang-questions