Reputation: 2596
I have come across the following code and don't understand it.
Dim bTemp as boolean = False
Dim License as integer = 2066350014
bTemp = aAreaLicence(1) And License
If aAreaLicence(1) = 64
then the boolean is set to false
If aAreaLicence(1) = 16
then the boolean is set to true
I have no idea what is happening here, can someone explain it please?
Upvotes: 2
Views: 62
Reputation: 27322
From the Docs
And Operator
Performs a logical conjunction on two Boolean expressions, or a bitwise conjunction on two numeric expressions.
So in your case you are having a bitwise conjunction.
64 And 2066350014
evaluates to 0
which is False
when converted to a Boolean value because it is Zero
16 And 2066350014
evaluates to 16
which is True
when converted to a Boolean value because it is Non-Zero
Upvotes: 2
Reputation: 335
Numbers Licences and aAreaLicence(1) are converted to binary and then operation "and" is executed on every bit. So:
2066350014 (10) = 1111011001010011111111110111110 (2)
64 (10) = 0000000000000000000000001000000 (2)
16 (10) = 0000000000000000000000000010000 (2)
If we execute "and" operation:
1111011001010011111111110111110
And
0000000000000000000000001000000
=
0000000000000000000000000000000 - that means 2066350014 And 64 = false
1111011001010011111111110111110
And
0000000000000000000000000010000
=
0000000000000000000000000010000 - that means 2066350014 And 16 = true
Upvotes: 4
Reputation: 8681
Decimal to Binary:
2066350014 = 1111011001010011111111110111110
64 = 1000000
16 = 10000
Then use Boolean algebra:
bTemp = aAreaLicence(1) And Licences = 64 AND 2066350014 = 0 = false
bTemp = aAreaLicence(1) And Licences = 16 AND 2066350014 = 16 = true
Upvotes: 1