Last active
March 17, 2021 02:24
-
-
Save louisswarren/7bdc84cbf2167440ec46fd83093e9f8a to your computer and use it in GitHub Desktop.
That's 65% more word per word
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
uint64_t | |
strtoword(char *s) | |
{ | |
uint64_t word = 0; | |
word |= ((uint64_t) *(s++) & 0x1f) << 55; | |
word |= ((uint64_t) *(s++) & 0x1f) << 50; | |
word |= ((uint64_t) *(s++) & 0x1f) << 45; | |
word |= ((uint64_t) *(s++) & 0x1f) << 40; | |
word |= ((uint64_t) *(s++) & 0x1f) << 35; | |
word |= ((uint64_t) *(s++) & 0x1f) << 30; | |
word |= ((uint64_t) *(s++) & 0x1f) << 25; | |
word |= ((uint64_t) *(s++) & 0x1f) << 20; | |
word |= ((uint64_t) *(s++) & 0x1f) << 15; | |
word |= ((uint64_t) *(s++) & 0x1f) << 10; | |
word |= ((uint64_t) *(s++) & 0x1f) << 5; | |
word |= ((uint64_t) *(s++) & 0x1f) << 0; | |
return word; | |
} | |
void | |
wordtostr(uint64_t word, char *s) | |
{ | |
*(s++) = 0x60 | (word >> 55) & 0x1f; | |
*(s++) = 0x60 | (word >> 50) & 0x1f; | |
*(s++) = 0x60 | (word >> 45) & 0x1f; | |
*(s++) = 0x60 | (word >> 40) & 0x1f; | |
*(s++) = 0x60 | (word >> 35) & 0x1f; | |
*(s++) = 0x60 | (word >> 30) & 0x1f; | |
*(s++) = 0x60 | (word >> 25) & 0x1f; | |
*(s++) = 0x60 | (word >> 20) & 0x1f; | |
*(s++) = 0x60 | (word >> 15) & 0x1f; | |
*(s++) = 0x60 | (word >> 10) & 0x1f; | |
*(s++) = 0x60 | (word >> 5) & 0x1f; | |
*(s++) = 0x60 | (word >> 0) & 0x1f; | |
*s = 0; | |
} | |
int | |
main(void) | |
{ | |
char test[13] = "equivalences"; | |
char out[13]; | |
uint64_t word = strtoword(test); | |
wordtostr(word, out); | |
printf("%s => %x => %s\n", test, word, out); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment