Skip to content

Commit

Permalink
Added a reference file to notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 authored Dec 26, 2024
1 parent cc4ff3f commit c3a737e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .notes/hash.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit c3a737e

Please sign in to comment.