Skip to content

Instantly share code, notes, and snippets.

@RolandWarburton
Created September 6, 2019 01:08
Show Gist options
  • Save RolandWarburton/5aefdf243ec7bac0c104d11ba092c726 to your computer and use it in GitHub Desktop.
Save RolandWarburton/5aefdf243ec7bac0c104d11ba092c726 to your computer and use it in GitHub Desktop.
SWE20004 assignment 1 encoder
void encode4PlusDigits(int value)
{
// slices an int number. eg.
// a[1,2,3] = a[1] = 2
int valueLen = to_string(value).length();
int sliced[valueLen];
for (int i = 0; i < valueLen; i++)
{
sliced[i] = value % 10;
value /= 10;
this->data.push_back((sliced[i] * 3) % 10);
}
// reverse the vector because i sliced the array the wrong way around
reverse(this->data.begin(), this->data.end());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment