lundi 25 septembre 2017

Padding a vector with 0's if it's not a multiple of 8

How can I pad out a vector with 0's if it is not a multiple of 8 bytes? In the following code I work out the offset and add to the vector to make sure it always has 8 values. I would like to pad this out with 0's and I am wondering what is the most efficient way to do this.

For example:

Input: 4444

With padding: 4444000000000000

The code I have so far is:

if ((vector1.size() % 8) != 0)
{
  for (std::vector<unsigned char>::iterator itr = vector1.begin(); itr != vector1.end(); itr ++)
  {
    vector1.push_back(fmod(vector1.size(), 8));

    if(vector1.size() == 8)
      break;
  }
}

Aucun commentaire:

Enregistrer un commentaire