Sunday, 15 March 2015

syntax - What does this ampersand mean in C? -



syntax - What does this ampersand mean in C? -

this question has reply here:

what bitwise operators? 9 answers c language code mean ? if(button & 1)==1 [closed] 4 answers

i looking @ c code:

if((var_on&3) > 1)

i not sure kind of variable var_on is, guess is pointer, &3 @ end it? apologize if duplicate question, not find question regarding ampersand after variable.

as used in question code, ampersand '&' bitwise 'and' operation.

example (assuming var_on = '21'):

var_on 21(decimal) 00010101(binary) & 3(decimal) & 00000011(binary) ------------ ------------------ 1(decimal) 00000001(binary)

hence if var_on '21', look (var_on&3) evaluate '1'. 'if' status false:

if((var_on&3) > 1)

c syntax

No comments:

Post a Comment