HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Is the codomain/range of a hash function always $\mathbb{Z}$ or $\mathbb{N}$?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
themathbbrangealwaysfunctionhashcodomain

Problem

From Wikipedia


A hash function is any algorithm or subroutine that maps large data
sets of variable length, called keys, to smaller data sets of a
fixed length. For example, a person's name, having a variable
length, could be hashed to a single integer. The values returned
by a hash function are called hash values, hash codes, hash sums,
checksums or simply hashes.

I wonder if the range/codomain of a hash function is always the set of natural numbers or integers, because their function values seem to be always used as indices to some array?

Solution

Range of any hash function is a sub-set of natural numbers (this is how we think of it, exactly for access to the arrays, that could lie behind). The actual output of common hash-functions (MD5, SHAX...) is $n$ bits, where $n$ is $128$ for MD5 and $512$ for SHA2 with 80 rounds.

These bits can then be interpreted as natural numbers from interval $[0, 2^n-1]$. They can also be interpreted as integer from $[-2^{n-1},2^{n-1}]$. They can also be interpreted as "strings", although in essence they are only bits. What @Arani is talking about (I think) is probably conversion of this binary number to the hexadecimal format, and viewing it as string.

Context

StackExchange Computer Science Q#6680, answer score: 6

Revisions (0)

No revisions yet.