forth-riscv

My forth
git clone git://git.electrosoup.com/forth-riscv
Log | Files | Refs

hash.c (441B)


      1 #include <stdio.h>
      2 #include <string.h>
      3 
      4 unsigned int fnv1a(unsigned char* str) {
      5     unsigned int hash = 2166136261;
      6     unsigned int len = strlen(str);
      7     for (int i = 0; i < len; i += 1) {
      8         hash = hash ^ (int)str[i];
      9         hash = hash * 16777619;
     10     }
     11     return hash;
     12 }
     13 
     14 int main(int arcg, char** argv) {
     15     unsigned char* str = argv[1];
     16     unsigned int hash = fnv1a(str);
     17     printf("hash: 0x%08X\n", hash);
     18     return 0;
     19 }