Skip to content

Use bit shifts instead of multiplication/division #7

Description

@hjerabek

In your reference C implementation you write

hash = 0x003C50DB * (*bytes++ ^ hash * 2 ^ hash / 2);

which should be equal to

hash = 0x003C50DB * (*bytes++ ^ (hash << 1) ^ (hash >> 1));

While the C compiler will probably optimize this by default, there is a number of programming languages, particularly script languages like JavaScript, where using bitwise operations instead of arithmetic ones can give a significant boost in performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions