Patrick Marchand is a user on bsd.network. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Patrick Marchand @mathuin
Follow

Any and / or peeps want to help me here?

I'm unfamiliar with bitwise operations. What would this the following code translate to in rust?

GBIT8(p) ((p)[0])
GBIT16(p) ((p)[0]|((p)[1]<<8))
GBIT32(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
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

· Web · 0 · 0

@deavmi Taken from <fcalll.h> from plan9port

@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

@mathuin

I made a demonstration of these macros in C: github.com/pgniewek/learn_gbit

You can interact with this code on the GDB online via this link: onlinegdb.com/Skv0mWP7X

Hope that helps 😉