## 3 replies

Last post Feb 20, 2012 01:30 PM by caponet

Member

2 Points

5 Posts

### Help with if statement

Hi,

Could someone help me to understand the logic behind this if statement?

Why the following statement returns true

`If (129025 And 2048) = 2048 Then`

and the following one returns false

```If (129025 And 512) = 512 Then
```

Thank you

Contributor

4617 Points

1036 Posts

### Re: Help with if statement

Feb 20, 2012 11:55 AM|Ramesh T|LINK

Hello Mate,

And operator (all logical operators) does bit wise operation,  if it used in between integers.

Below is wat exactly u r doing

11111100000000001(129025 ) & 00000100000000000(2048) = 00000100000000000(2048)

and

11111100000000001(129025 ) & 00000001000000000(512) = 00000000000000000(0) which is not equal to 00000001000000000(512)

Contributor

5274 Points

1083 Posts

### Re: Help with if statement

The result has to do with binary "AND"

for the first case:

If (129025 And 2048) = 2048 Then

Binary of 129025 : 11111100000000001

Binary of 2048: 00000100000000000

when you "AND" this, you get "00000100000000000" equal to binary of 2048 so you get true.

second case:

If (129025 And 512) = 512 Then

Binary of 129025 : 11111100000000001

Binary of 512 : 00000001000000000

when you "AND" this, you get "00000000000000000" not equal to binary of 512 so you get false.

Sandeep Mittal | My Blog - IT Developer Zone

Member

2 Points

5 Posts