I have a binary file that I am trying to extract data from. The last 5 data points int the file are 10 bit integer types and I am struggling on how to extract that information and convert it into something readable. I have tried the following code:
struct bitField
{
unsigned value: 10;
};
struct Data
{
bitField x;
}
int main()
{
std::array<char,696> buffer;
std::ifstream file ("file.bin", std::ios::in | std::ios::binary);
file.read(buffer.data(),buffer.size());
Data a;
std::memcpy(&a.x.value,&buffer[612],sizeof(struct bitField));
}
I am then met with the error attempt to take address of bit-field. I have then tried using std::bitset<10> in place of bitField in my Data struct. And while I do not get a compiler error, I get back a bunch of 0's instead which I believe is incorrect data.
How do you properly read in the data?