mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
14 lines
442 B
Plaintext
14 lines
442 B
Plaintext
Returns a basic +n+-bit {checksum}[https://en.wikipedia.org/wiki/Checksum] of the characters in +self+;
|
|
the checksum is the sum of the binary value of each byte in +self+,
|
|
modulo <tt>2**n - 1</tt>:
|
|
|
|
'hello'.sum # => 532
|
|
'hello'.sum(4) # => 4
|
|
'hello'.sum(64) # => 532
|
|
'тест'.sum # => 1405
|
|
'こんにちは'.sum # => 2582
|
|
|
|
This is not a particularly strong checksum.
|
|
|
|
Related: see {Querying}[rdoc-ref:String@Querying].
|