How can I convert a integer to its bit representation. I want to take an integer and return a vector that has contains 1\'s and 0\'s of the integer\'s bit representation.
Doesn't work with negatives.
vector convert(int x) { vector ret; while(x) { if (x&1) ret.push_back(1); else ret.push_back(0); x>>=1; } reverse(ret.begin(),ret.end()); return ret; }