Hash Code and Checksum - what's the difference?

后端 未结 13 1728
天命终不由人
天命终不由人 2020-12-04 07:29

My understanding is that a hash code and checksum are similar things - a numeric value, computed for a block of data, that is relatively unique.

i.e. The pr

相关标签:
13条回答
  • 2020-12-04 08:05

    Hashcodes and checksums are both used to create short numerical value from a data item. The difference is that a checksum value should change, even if a small modification is made to the data item. For a hash value, the requirement is merely that real-world data items should have distinct hash values.

    A clear example are strings. A checksum for a string should include each and every bit, and order matters. A hashcode on the other hand can often be implemented as a checksum of a limited-length prefix. That would mean that "aaaaaaaaaaba" would hash the same as "aaaaaaaaaaab", but hash algorithms can deal wth such collisions.

    0 讨论(0)
提交回复
热议问题