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 7651179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:26:32+00:00 2026-05-31T11:26:32+00:00

here i have code for calculate hash value of unsigned char #include <cstdlib> #include

  • 0

here i have code for calculate hash value of unsigned char

#include <cstdlib>
#include <iostream>
#include<string.h>
using namespace std;

unsigned oat_hash(unsigned char *key,int len)
{
    unsigned char *p=key;
    unsigned h=0;
    int i;
    for(i=0;i<len;++i){
        h+=p[i];
        h+=(h<<10);
        h^=(h>>6);
    }
    h+=(h<<3);
    h^=(h>>11);
    h+=(h<<15);

    return h;
}

using namespace std;

int main(int argc, char *argv[])
{
    unsigned char mystring[]="123456789abcdef";
    unsigned char *key=&mystring[0];
    int n=sizeof(mystring)/sizeof(mystring[0]);//length of mystring
    cout<<oat_hash(key,n)<<endl;
    //system("PAUSE");
    //return EXIT_SUCCESS;
    return 0;
}

name of this hash function is so called One-at-a-Time hash(by Bob Jenkins) i have one question is this little part of code correct?

int n=sizeof(mystring)/sizeof(mystring[0]);//length of mystring

because mysting has not built-in function length,i used this

  • 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-05-31T11:26:34+00:00Added an answer on May 31, 2026 at 11:26 am

    Under the circumstances, yes — but it’s pretty fragile. For example, if you changed your definition from:

    unsigned char mystring[]="123456789abcdef";
    

    To:

    unsigned char *mystring="123456789abcdef";
    

    Your method of finding the length would produce completely incorrect results. Also note that since your string is made up of chars, the /sizeof(mystring[0]) isn’t really necessary either — sizof(char) == 1 (and the same for signed char or unsigned char).

    You normally want to use strlen instead.

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

Sidebar

Related Questions

i have this code right here: <select name=group> <option value=>Choose a group....</option> <?php foreach($groups
I want to calculate the power of 2 using recursion. Here is my code:
The code that I have here is using a MouseAdapter to listen for the
I have some problems with the SHA1 hash value of a string. I'm trying
Here is my issue. I have an ASPX web site and I have code
Please help me to rectify my code. Here I have described the code what
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
I have this code here, which is intended to allow any type of arguments:
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
I have some code here which works perfectly in firefox but not in chrome

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.