Urgent C++ string related

Alright I was able to code a factor that starts at 1 and goes up the length of the string:
1
2
3
4
5
6
7
8
9
10
11
12
uint64_t hash_bytes(const char* bytes, size_t length)
{
    uint64_t sum = 0;

    for(size_t i = 0; i < length; i++)
    {
        uint64_t factor = i + 1;
        sum += (factor * bytes[i]);
    }

    return sum;
}



My current issue is that I do not know how to code this: and any example would be great!
factor starts at the length of the string (M) and goes down to 1.
Last edited on
Do you mean, replace line 7 with this?

uint64_t factor = length - i;
Topic archived. No new replies allowed.