c - How to cast long unsigned to unsigned char*? -


i trying hash unsigned long value, hash function takes unsigned char *, seen in implementation below:

unsigned long djb2(unsigned char *key, int n) {     unsigned long hash = 5381;     int = 0;     while (i < n-8) {         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];         hash = hash * 33 + key[i++];     }     while (i < n)         hash = hash * 33 + key[i++];     return hash; } 

is there way can achieve goal, perhaps cast between two?

unsigned long x;  unsigned char * p = (unsigned char*)&x; 

make sure use 4 bytes through p, or whatever length of unsigned long on system.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -