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.
Returns a string instead of a vector, but can be easily changed.
template std::string get_bits(T value) { int size = sizeof(value) * CHAR_BIT; std::string ret; ret.reserve(size); for (int i = size-1; i >= 0; --i) ret += (value & (1 << i)) == 0 ? '0' : '1'; return ret; }