C++ – 1 byte unsigned integer c++

c++

I have programmed a class called HugeInteger which can do arithmetic (add, sub, multiply) with numbers of "infinitely" size. It treats each bit of the digit in the number as a stand-alone digit (e.g. 1234 = 1, 2, 3 and 4). I store these numbers in a vector (vector<short>). Now, because each digit only can take the values from 0 to 9, i don't really need to store them as a 2 byte digit. Is there a way (without using char) to store the digits as a 1 byte unsigned integer? Thanks!

Update:

vector<unsigned char> v;
v.push_back(1);
v.push_back(2);

for (size_t i = 0; i < v.size(); i++)
    cout << v[i];

This produces an unwanted output. Which datatype should I use to iterate through the vector?

Best Solution

Yes, use unsigned char.

If <stdint.h> is available, then you could also use uint8_t.