Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:18:14+00:00 2026-06-06T06:18:14+00:00

I’m trying to integrate FNV hashing algorithm on a PHP-based project as part of

  • 0

I’m trying to integrate FNV hashing algorithm on a PHP-based project as part of a requirement to produce hashes for a variety of data (e.g. URLs, keywords).

I saw this implementation by Neven Boyanov. He mentioned that due to arithmetic limitations in PHP, he was forced to use bitwise-shifting and addition instead of multiplication. Is his implementation correct? My knowledge is somehow limited in this area of computer science so I can’t verify it myself.

Another question that I have is about the different ‘flavors’ of FNV. I saw that it offers 32-bit, 64-bit, and 128-bit variants but using the above implemention I always get 8-character hex hashes (I convert the integer result to hex using dechex()).

Given the input “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin at libero mi, quis luctus massa.”, I get the following hex results:

  • (32-bit offset) 5b15c0f2
  • (64-bit offset) 6ea33cb5

Why is this so? I’m expecting a 16-character hex result from the 64-bit FNV. Are the ‘flavors’ referring only to the kind of arithmetic operations and seeds that would be used and not to the length of the result? (i.e. if I say 64-bit FNV, the hashing function would use 64-bit operations and seed but the result would still be 32-bit)

A bit of enlightenment would be greatly appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:18:15+00:00Added an answer on June 6, 2026 at 6:18 am

    I wrote PHP FNV hash function long ago and it was for a particular purpose, so at that time the 32-bit implementation was sufficient.

    To answer your first question – the implementation was tested against other (C and C++) implementations by comparing the algorithm (code) and sample results. So for 32-bit results it works as it should.

    If you want to implement the 64-bit (or 128-bit) version yourself you should change first the FNV_offset_basis but also the expression on line 73 which currently is:

    $hash += ($hash<<1) + ($hash<<4) + ($hash<<7) + ($hash<<8) + ($hash<<24);
    

    … this is equivalent of multiplying by the number 16777619 (FNV_prime_32) which in binary is 1000000000000000110010011 – broken down to this expression: 2^24 + 2^8 + 2^7 + 2^4 + 2^1 + 2^0.

    For 64-bit you should multiply by 1099511628211 – binary 10000000000000000000000000000000110110011 … expression: 2^88 + 2^8 + 2^7 + 2^5 + 2^4 + 2^1 + 2^0.

    I don’t know how the expression $hash << 88 will be handled by PHP but you should experiment yourself. On my PHP 5.2.x it did not work well for numbers greater than 31.

    Finally, you may need to modify the $hash = $hash & 0x0ffffffff; to remove some garbage from the result. I figured that out through experiments. For the 64-bit ot should be like $hash = $hash & 0x0ffffffffffffffff;. Verify if it works correctly with PHP.

    You can also use other PHP libraries for higher arithmetic precision. In my opinion using bitwise shifts is faster.

    In fact you can product FNV Hash for any number of bits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.