0

I've been working on this for hours but I still can't get my methods to work no matter how many times I look over bitwise functions. (Switching it to just pos throws an error).

Bits() = default;

Bits(IType n) {

    bits = n;

}

void set(int pos) {

    (bits |= 1ULL << (pos-1));
}

void reset(int pos) {      // Resets (makes zero) the bit at position pos
    bits  &= ~(1ULL << (pos-1));
}

This is what I get when I try to submit it For some reason it seems to be filling out the bit with the entire long.

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
  • 2
    Is `pos` actually 1-up? Or can it be `0`? Also, what is `bits`? Looks like it's a templated type. Weird stuff can happen if it's signed... – ShadowRanger Mar 11 '21 at 03:04
  • http://www.graphics.stanford.edu/~seander/bithacks.html – LIU Qingyuan Mar 11 '21 at 03:27
  • I find this is a perfect cheat sheet fot tricky bitwise ops. – LIU Qingyuan Mar 11 '21 at 03:28
  • 2
    @LIUQingyuan I don't see how the Bit hacks apply to OPs question. What he tries to do are most basic bit manipulations... [**How do you set, clear, and toggle a single bit?**](https://stackoverflow.com/q/47981/7478597) – Scheff's Cat Mar 11 '21 at 07:14

0 Answers0