Search code examples
c++user-defined-data-types

How to convert different data-types to bytes in c++?


I have a structure that looks like:

typedef struct{
  float distance;
  float reflectivity;      
}data_point;

typedef struct{
  int flag;
  float Azimuth;
  data_point points[32];
}data_block;
  • A data point is represented in the packet by three bytes - two bytes of distance and one byte of calibrated reflectivity. The distance is an unsigned integer. It has 2 mm granularity. Hence, a reported value of 51,154 represents 102,308 mm or 102.308 m. Calibrated reflectivity is reported on a scale of 0 to 255. The elevation angle (ω) is inferred based on the position of the data point within a data block.
  • flag from float to 2 bytes(constant 0xFFEE)
  • A two-byte azimuth value (α) appears after the flag bytes at the beginning of each data block. The azimuth is an unsigned integer. It represents an angle in hundredths of a degree. Therefore, a raw value of 27742 should be interpreted as 277.42°

enter image description here

enter image description here

How can I create a vector of 100 bytes of binary data? ( 2 + 2 + (32x3))?


Solution

  • You can either: