From afb48b65b9217fd0afd7d53cd89365d11a5a556b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 9 Apr 2024 15:10:40 +0630 Subject: Completed TODO: Rigid Endian Just used the endian.h functions to convert host endian to and from big endian. --- lib/base.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib/base.c') diff --git a/lib/base.c b/lib/base.c index 14a250e..b7a6ed5 100644 --- a/lib/base.c +++ b/lib/base.c @@ -10,30 +10,35 @@ * Description: Implementation of basic library functions */ +#include #include #include "./base.h" hword convert_bytes_to_hword(byte *bytes) { - hword h = 0; - memcpy(&h, bytes, HWORD_SIZE); + hword be_h = 0; + memcpy(&be_h, bytes, HWORD_SIZE); + hword h = be32toh(be_h); return h; } void convert_hword_to_bytes(hword w, byte *bytes) { - memcpy(bytes, &w, HWORD_SIZE); + hword be_h = htobe32(w); + memcpy(bytes, &be_h, HWORD_SIZE); } void convert_word_to_bytes(word w, byte *bytes) { - memcpy(bytes, &w, WORD_SIZE); + word be_w = htobe64(w); + memcpy(bytes, &be_w, WORD_SIZE); } word convert_bytes_to_word(byte *bytes) { - word w = 0; - memcpy(&w, bytes, WORD_SIZE); + word be_w = 0; + memcpy(&be_w, bytes, WORD_SIZE); + word w = be64toh(be_w); return w; } -- cgit v1.2.3-13-gbd6f