difference between bitwise or and bitwise and

I was looking at some documentation and it says the following:

Bitwise AND assignment a &= b
Bitwise OR assignment a |= b

But it isn't too helpful.

I have some code that looks like this:

quint64 value = 0;
byte = data.at(*idx);
if (big_endian == true) {
value |= byte << ((size - i - 1) * 8);
}

I'm not sure what "|=" is doing. Any idea?
Do you know what && and || do?
Do you know how numbers are represented in binary?
1
2
3
a |= b;
// does same as
a = a | b;

Result of OR is 1 if at least one of the two bits is one.
Result of AND is 1 only if both of the two bits are one.
Result of XOR is 1 if exactly one of the two bits is one.

I presume that you have 64 bits in quint64. When you have two of those, you have 64 pairs of bits in bitwise operation.

For example:
5 | 3 == 7
5 & 3 == 1
// in binary:
  0101
  0011
|
  0111

  0101
  0011
&
  0001


Edit: If value==0, then value != number; should be same as value = number;
Last edited on
Topic archived. No new replies allowed.