Linked Questions

15 votes
6 answers
4k views

What are the | and ^ operators used for? [duplicate]

Possible Duplicate: What are bitwise operators? Recently I came across a few samples that used the | and ^ operators. I am guessing these are or and negation operators. So what actually do these ...
Simsons's user avatar
  • 12.5k
8 votes
2 answers
1k views

What does the "^=" operator do in this find non-paired number algorithm? [duplicate]

Saw an interesting piece of code to find a lonely number in a list of duplicate numbers (where every number in the list occurs twice except for one). function findNonPaired(listOfNumbers) { ...
Cumulo Nimbus's user avatar
4 votes
4 answers
9k views

boolean operations with integers [duplicate]

This is probably pretty basic... but I don't seem to get it: How does (2 & 1) = 0 (3 & 1) = 1 (4 & 1) = 0 etc.. This pattern above seems to help find even numbers or (0 | 1) = 1 (1 ...
user avatar
3 votes
3 answers
1k views

What does this ampersand mean in C? [duplicate]

I am looking at the c code: if((VAR_ON&3) > 1) I am not sure what kind of variable VAR_ON is, my guess is it is a pointer, but what does the &3 at the end do to it? I apologize if this ...
TheBlindSpring's user avatar
3 votes
2 answers
160 views

Understanding the | operator in scala [duplicate]

I came to code: scala> val a = 0 | 1 a: Int = 1 scala> val a = 0 | 1 | 2 a: Int = 3 scala> val a = 0 | 1 | 2 | 3 a: Int = 3 scala> val a = 0 | 1 | 2 | 3 | 4 a: Int = 7 The only ...
Evhz's user avatar
  • 9,038
4 votes
3 answers
190 views

How bitwise operator works [duplicate]

I dont get how the following codes work? function odd($var){ return ($var & 1); } echo odd(4); /* returns and print 0 */ echo odd(5); /* returns and print 1 */ this function returns true if ...
partho's user avatar
  • 1,131
0 votes
1 answer
958 views

Javascript Bitwise to Regular Operators [duplicate]

I have been recently reading this book, "Supercharged Javascript Graphics", and it is just awesome. It has some really interesting concepts and examples using html5 canvas element and other graphics. ...
lomas09's user avatar
  • 1,104
1 vote
1 answer
1k views

In C - what does if(ptr->name & 0x10) mean [duplicate]

Newbie on C language. I understand pointers and hex format but I'm not sure what '& 0x10' is doing. Could someone kindly explain it or advise me on topics to research and teach myself. Thank you. ...
Krn's user avatar
  • 13
0 votes
3 answers
357 views

if (index & 0x88) == 0, how this works? [duplicate]

Can anyone show me how this operation works? Index is number and it can be any number from 0 to 128. I just don't understand how (index & 0x88) can be 0 or not. Any help will be greatly ...
user2313976's user avatar
2 votes
2 answers
237 views

what the meaning of (a&b)>>c in this systemc code? [duplicate]

when I read SYSTEMC code,I find a function return int like this: static inline int rp_get_busaccess_response(struct rp_pkt *pkt) { return (pkt->busaccess_ext_base.attributes & ...
celia's user avatar
  • 25
1 vote
1 answer
244 views

Why do we use the bitwise or operator when we want to combine re.IGNORECASE and re.DOTALL? [duplicate]

From my textbook (automate the boring stuff, Al Sweigart): "If you want a regular expression that's case-insensitive and includes newlines to match the dot character, you would form your re....
aurumpurum's user avatar
  • 1,002
0 votes
2 answers
322 views

Javascript bitwise operators - explanation required [duplicate]

I'm using some code in JS and I bumped into these (unrelated) expressions: 1) var r = (d + Math.random() * 16) % 16 | 0; 2) return c === 'x' ? r : (r & 0x3 | 0x8); I read some about bitwise ...
Huqe Dato's user avatar
  • 255
-3 votes
3 answers
369 views

Explanation of Output of Bitwise operations [duplicate]

void main() { int x=7; printf("%d",x&(x-1)); int y=6; printf("%d",y&(y-1)); printf("%d",y>>2); } When I put an odd number I get output n-1 where n is a odd number but when i put ...
user2665256's user avatar
0 votes
1 answer
202 views

C programming Bitwise operator &= struggling to understand what its doing [duplicate]

I am trying to work out how this part of this code is working. REF state &= 0X07; static uint8_t state = 0; /* values for half step 0001, 0011, 0010, 0110, 0100, 1100, 1000, 1001*/...
johnnyh20's user avatar
0 votes
3 answers
82 views

How does bitwise 'or' becomes a '+=' in bytecode for python [duplicate]

I was reading the following explanation of python bytecode. I'm posting a lot in order to give the full context. I'm confused about the part where the bitwise 'or' becomes a '+='. EXTENDED_ARG 1 ...
Joemoor94's user avatar
  • 173

15 30 50 per page