Whats the difference when your using bitwise operators and logical operators in a conditional statements?
if ((val==1)|(val==2)) printf("%d\n",val);
if ((val==1)||(val==2)) printf("%d\n",val);
Which do you think is better and why is that? Thanks again for the replies ^_^
>>i found this/
someone correct me if I'm wrong: both bitwise and logical operators are the representation of the boolean function with the same names(better read on that first as I suspect the fact that you haven't) the diference is that the bitwise ones operate on bits(it doesn't matter if your data type has 8,16,32 or 64 bits, the operation is applied to every bit of the operands e.g 1|1 =1 10|01 =11, 100|1 = 101 and so on), where as the logical operators operate on logical atoms( the whole atom is considered as a bit, the interpreted values are false for 0 and true for non-zero values)
^ basically right, except that nowhere does Java define any mapping between 0 and 1s vs the boolean values false/true.
Bitwize operators work on each bit of an int value, the logical operators work on individual boolean true/false values, but there's no connection between these two versions.
Ohh, When i asked this question, it was almost midnight in my country :) I think this is the reason why i did not understand the difference. Now I am so regretful for asking this simple question. Thank you all guys.