But Bit.And(8,12) = 12 will result in False. In most languages that have an implicit Int to Boolean conversion, both ways would result in True.It is normal that Bit.And(12,8) = 8 is True. If you compare to 0, then it is not necessary to use this operator. Just check test_1 = test_2.
'Most Languages
If (8 & 12) Then 'True
If (12 & 8) Then 'True
If (8 & 16) Then 'False as 8 AND 16 = 0
'Method #1
If Bit.And(12,8) = 8 Then 'True
If Bit.And(8,12) = 12 Then 'False
If Bit.And(8,16) = 16 Then 'False
'Method #2
If Bit.And(12,8) <> 0 Then 'True
If Bit.And(8,12) <> 0 Then 'True
If Bit.And(8,16) <> 0 Then 'False
I deleted my message because I answered too quickly. Here's my answer:But Bit.And(8,12) = 12 will result in False. In most languages that have an implicit Int to Boolean conversion, both ways would result in True.
As you can see, method 2 gives similar results to other languages. Also, Test_1 = Test_2 would not work as Test_1 = 8 and Test_2 = 12 would result in false instead of true.B4X:'Most Languages If (8 & 12) Then 'True If (12 & 8) Then 'True If (8 & 16) Then 'False as 8 AND 16 = 0 'Method #1 If Bit.And(12,8) = 8 Then 'True If Bit.And(8,12) = 12 Then 'False If Bit.And(8,16) = 16 Then 'False 'Method #2 If Bit.And(12,8) <> 0 Then 'True If Bit.And(8,12) <> 0 Then 'True If Bit.And(8,16) <> 0 Then 'False
No, because you don't know what you are checking by comparing to 0. When I write the following, I check explicitely test_2.:might be better to do Log (Bit.and(test_1,test_2) <> 0) for a result more consistent with other languages, where a 0 results in false and all other values result in true, so test_1 = 8 and test_2 = 12 will still result in true.
Since we don't know what Artur is trying to accomplish, it is quite possible that your solution is perfect for his needs; however, it is not the way most languages behave. In most languages, you can have If Bit.and(8,12) Then ...Example:
Log(Bit.AND(12,8) = 12)
Log(Bit.AND(12,8) <> 0)
Result:
False
True (why true?)
??? Please read what Bit.And does.I would avoid all this, because a simple:
If a = x And b = y Then
is more readable
then I will use the binary operators for their purpose.
Absolutely. It's all about clarity of code.maybe I am understanding it wrong, but it seems to me you are discussing on how to use the result from Bit.AND that IMHO should be up to the programmer.
Please read what Bit.And does.
Yes, so what's the relationship with your example (If a = x And b = y Then)?Bit.And (Or...) works on bits, then performs binary operations.
might be better to do Log (Bit.and(test_1,test_2) <> 0) for a result more consistent with other languages, where a 0 results in false and all other values result in true, so test_1 = 8 and test_2 = 12 will still result in true.
How do you convert the examples given in post #6 with the logical And operator? It's impossible.
Example:
Log(Bit.AND(12,8) = 12)
Log(Bit.AND(12,8) <> 0)
Result:
False
True (why true?)
There's a confusion here between logical operators and binary operators...If (Test_1 And Test_2) Then