From 9a317e56f8a6126583f7d0c431bf878d9b1fe7b1 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 8 Jul 2023 12:30:21 +0800 Subject: Finished the Emacs binding. Now the binding part is finished. What remains is a bug encountered when planting a fragment to the forest which intersects a packed node, which would lead to invalid forests. This will also cause problem when planting a packed fragment, but until now my testing grammars do not produce packed fragments, so this problem is not encountered yet. I am still figuring out efficient ways to solve this problem. --- src/big_endian.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/big_endian.c (limited to 'src/big_endian.c') diff --git a/src/big_endian.c b/src/big_endian.c new file mode 100644 index 0000000..2db8624 --- /dev/null +++ b/src/big_endian.c @@ -0,0 +1,28 @@ +#include "big_endian.h" + +void to_big_endian(uint64_t num, unsigned char *result) +{ + *(result+0) = (num >> 56) & 0xff; + *(result+1) = (num >> 48) & 0xff; + *(result+2) = (num >> 40) & 0xff; + *(result+3) = (num >> 32) & 0xff; + *(result+4) = (num >> 24) & 0xff; + *(result+5) = (num >> 16) & 0xff; + *(result+6) = (num >> 8) & 0xff; + *(result+7) = (num >> 0) & 0xff; +} + +uint64_t from_big_endian(unsigned char *num) +{ + uint64_t result = ((uint64_t) (*num) << 56); + + result += ((uint64_t) (*(num+1)) << 48); + result += ((uint64_t) (*(num+2)) << 40); + result += ((uint64_t) (*(num+3)) << 32); + result += ((uint64_t) (*(num+4)) << 24); + result += ((uint64_t) (*(num+5)) << 16); + result += ((uint64_t) (*(num+6)) << 8); + result += ((uint64_t) (*(num+7)) << 0); + + return result; +} -- cgit v1.2.3-18-g5258