-1

I am very new to c++ programming. I need to fill in the header fields, one of which is bitmapped field with 4 subfield. I don't know to create the value for that field. Can someone help me out please?

Below Text explains in detail:

Properties is a Bitmapped field with four subfields. The most significant bit shall be used to indicate whether or not receipt of the message shall be acknowledged. When the bit is “1,” an acknowledgement shall be sent: if “0,” an acknowledgement shall not be sent. The next seven bits (bits 14:8) shall indicate the IDD version number.

No ACK = 0, ACK =1
15 - Most Significant bit

Version
Range 0......127
Draft STANAG 4586 Edition 3 for Ratification = 30 Future Drafts/Editions...31 -127
14 13 12 11 10   9 8 - bits position

Checksum Length
No Checksum =0
2 bytes = 01 4 bytes = 10
7 6 - - bits position

Reserved for Future Use
543210 - - bits position

Thanks

Heavy
  • 1,861
  • 14
  • 25
User
  • 1,186
  • 4
  • 22
  • 36
  • Look at bitwise operators for and, and or (`&`, `|`), and shifting `<<`, `>>`. With a combination of these you can create and parse the bitmapped fields you need. – Colin Jan 10 '17 at 09:20
  • Possible duplicate of [How do you set, clear and toggle a single bit in C/C++?](http://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c-c) – Colin Jan 10 '17 at 09:21
  • If I define my 7 bit field like this struct bits { unsigned int a:1; unsigned int b:1; unsigned int c:1; unsigned int d:1; unsigned int e:1; unsigned int f:1; unsigned int g:1; }; How would I assign value 30 to this bit set? – User Jan 10 '17 at 09:31

1 Answers1

1

What you are looking for is called a "bit field" in C and C++. See MSDN or cppreference for explanation and examples.

struct YourBitField
{
   AckOrNack : 1;
   IDD : 7;
   // more here
}
nvoigt
  • 75,013
  • 26
  • 93
  • 142