bobber205 bobber205 - 1 year ago 98
C++ Question

Converting integer to a bit representation

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.

I'm having a heck of a time trying to do this myself so I thought I would ask to see if there was a built in library function that could help.

dcp dcp
Answer Source

Doesn't work with negatives.

vector<int> convert(int x) {
  vector<int> ret;
  while(x) {
    if (x&1)
  return ret;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download