Any #rust and / or #c peeps want to help me here?
I'm unfamiliar with bitwise operations. What would this the following code translate to in rust?
#define GBIT8(p) ((p)[0])
#define GBIT16(p) ((p)[0]|((p)[1]<<8))
#define GBIT32(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
#define GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
Ideally I'd want it to be safe
@deavmi Taken from <fcalll.h> from plan9port
@mathuin you run p9?
@mathuin if p is a pointer to a buffer of bytes. These macros will read bytes, words, etc. from that buffer. GBIT16 for instance will read the first two bytes and combine them into a word. The first byte will be the least significant one
I made a demonstration of these macros in C: https://github.com/pgniewek/learn_gbitx
You can interact with this code on the GDB online via this link: https://www.onlinegdb.com/Skv0mWP7X
Hope that helps 😉
@mathuin that's a lot of bit shifts