Example: For a set of six status inputs as shown for the ASCII data file in subclause 6.4.(0,0,0,0,1,1), a) Write these status inputs as a binary number (110000), recognizing that the channels are listed low bits first in the ASCII data file. b) Then pad the number out to a 16 bit number (0000 0000 0011 0000). c) Translate this to a hexadecimal value (00 30). d) The data is then stored in LSB/MSB format (30 00). 

Explain, please, how to record? There is a file with such lines:

 110000 110100 110001 

It is necessary to correctly write each line. How to implement it in c ++.

  • Which item is not clear to you? - nick_n_a
  • Point d) you have already asked ru.stackoverflow.com/questions/809953/… - nick_n_a
  • one
    Moreover, I even answered there everything seemed to be in detail - vegorov
  • I translate a) enter a number. b) add zeros c) translate to hex-form d) translate from "left-sided" to "right-sided" (reverse bytes). - nick_n_a
  • @vegorov already read, this is a double. Session - will be difficult. - nick_n_a

1 answer 1

@nick_n_a I write a binary file, and only the first 6 elements of the vector are written correctly 30 00, the remaining values ​​are 00 00 Recorded the vector and file.

 input.txt 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 void writeVector(std::istream &Dfile) { std::copy(std::istream_iterator<int>(Dfile), std::istream_iterator<int>(), std::back_inserter(vectorValue)); std::copy(vectorValue.begin(), vectorValue.end(), std::ostream_iterator<int>(std::cout, " ")); }; for (size_t i = 0; i < 7; i++) { int index = i + 1; file.write((char *)&index, sizeof(int)); unsigned short m_bytesCount = 0; for (size_t k = 1; k < 6; ++k) { if (vectorValue[++i2] == 1) m_bytesCount |= 1 << i2; else m_bytesCount = 0; } file.write((char *)&m_bytesCount, sizeof m_bytesCount); } 
  • it needs to be written in the question section, the answer section is for answers. - nick_n_a
  • why do you reset m_bytesCount = 0; ? And what is i2 ? - vegorov