Bit Fields in C++

Whether we are dealing with network protocols or device drivers, system-level programming often involves bit fields. As a system programming language, C offers a concise syntax to specify bit fields in C strctures, for example struct CStylePacket { u16 a : 3 ; u16 b : 9 ; u16 c : 2 ; } ; Here and in the following examples we are using the short type names popularized by Rust: using u32 = std ::…