Added a reference file to notes

This commit is contained in:
2024-12-26 17:13:46 +11:00
committed by GitHub
parent cc4ff3f6d8
commit c3a737eae5

23
.notes/hash.c Normal file
View File

@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdint.h>
uint32_t hash (uint32_t x) {
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x);
return x;
}
uint32_t unhash ( uint32_t x ) {
x = (( x >> 16) ^ x) * 0x119de1f3;
x = (( x >> 16) ^ x) * 0x119de1f3;
x = (( x >> 16) ^ x);
return x;
}
int main() {
//I legit didn't know this algorithm could be reversed. Neat.
uint32_t value = 42;
printf("%u %u %u", value, hash(value), unhash(hash(value)));
return 0;
}