user81257: I want to build structure of record. The problem is that I can't build the address field correctly. Can any one help me?
P.s: the address[16:2] is start from bit 61 to bit 47 so please you can't say you should shift it by 32.


user4143: For this I would use bit fields:
typedef union {
    struct {
        uint8_t raw[8]; // Raw access to the bytes
    };
    struct {
        unsigned data:32;
        unsigned cs14:1;
        unsigned cs13:1;
        unsigned cs12:1;
        unsigned cs11:1;
        unsigned cs10:1;
        unsigned cs9:1;
        unsigned cs8:1;
        unsigned cs7:1;
        unsigned cs6:1;
        unsigned cs5:1;
        unsigned cs4:1;
        unsigned cs3:1;
        unsigned cs2:1;
        unsigned cs1:1;
        unsigned cs0:1;
        unsigned address:15;
        unsigned parity:1;
        unsigned stop:1;
    };
    struct {
        unsigned :32;
        unsigned cs:15;
        unsigned :17;
    };
} Packet;

Then you can:
Packet p;
p.data = 0x493DE26CUL;
p.address = 0x13f3;
p.cs3 = 1;
// or
p.cs = 0x0080;

etc.

81257: <p>I want to build structure of record. The problem is that I can't build the address field correctly. Can any one help me?</p>
<p>P.s: the address[16:2] is start from bit 61 to bit 47 so please you can't say you should shift it by 32.</p>
<p><a href="https://i.stack.imgur.com/ETaJY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ETaJY.png" alt="the Record that I want to Build" /></a></p>
 4143: <p>For this I would use <em><a href="https://en.cppreference.com/w/cpp/language/bit_field" rel="nofollow noreferrer">bit fields</a></em>:</p>
<pre class="lang-cpp prettyprint-override"><code>typedef union {
    struct {
        uint8_t raw[8]; // Raw access to the bytes
    };
    struct {
        unsigned data:32;
        unsigned cs14:1;
        unsigned cs13:1;
        unsigned cs12:1;
        unsigned cs11:1;
        unsigned cs10:1;
        unsigned cs9:1;
        unsigned cs8:1;
        unsigned cs7:1;
        unsigned cs6:1;
        unsigned cs5:1;
        unsigned cs4:1;
        unsigned cs3:1;
        unsigned cs2:1;
        unsigned cs1:1;
        unsigned cs0:1;
        unsigned address:15;
        unsigned parity:1;
        unsigned stop:1;
    };
    struct {
        unsigned :32;
        unsigned cs:15;
        unsigned :17;
    };
} Packet;
</code></pre>
<p>Then you can:</p>
<pre class="lang-cpp prettyprint-override"><code>Packet p;
p.data = 0x493DE26CUL;
p.address = 0x13f3;
p.cs3 = 1;
// or
p.cs = 0x0080;
</code></pre>
<p>etc.</p>
