Why is the bit-pattern 001/010/100/000/101 for 5381 significant

ghz 8months ago ⋅ 68 views

Why is the bit-pattern 001/010/100/000/101 for 5381 significant in the magic constant in the djb2 hash function?

The reason for the number 5381 in the djb hash function was partly answered:

Magic Constant 5381: 
1. odd number
2. prime number
3. deficient number
4. 001/010/100/000/101 b

I am new to C and programming. I hope this is not too small a question as I do not have enough reputation to comment.

What does 001/010/100/000/101 b mean and what is its relevance to the question linked above?

Thank you

Answers

Certainly! The notation "001/010/100/000/101 b" represents a binary number. Each digit in a binary number represents a power of 2, with the rightmost digit being 2^0 (1), the next digit to the left being 2^1 (2), then 2^2 (4), and so on, doubling with each position to the left.

Breaking down "001/010/100/000/101 b":

  • "001" in binary represents the decimal number 1. In binary, it's 2^0.
  • "010" in binary represents the decimal number 2. In binary, it's 2^1.
  • "100" in binary represents the decimal number 4. In binary, it's 2^2.
  • "000" in binary represents the decimal number 0. No powers of 2 are added here.
  • "101" in binary represents the decimal number 5. It's 2^2 (4) + 2^0 (1).

So, "001/010/100/000/101 b" indicates a sequence of decimal numbers derived from binary digits in each group.

Regarding its relevance to the question about the DJB hash function and the magic constant 5381:

The magic constant 5381 is often used in hash functions for its properties, such as being an odd prime number. The binary representation "001/010/100/000/101 b" simply provides a different perspective on the binary representation of the decimal number 5381. It's not directly related to the properties of the number itself but rather a way to represent it in binary form.