# Help with if statement RSS

## 3 replies

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

Member

4 Points

4 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

• Edited by caponet on Feb 20, 2012 11:36 AM
• Moved by XIII on Feb 20, 2012 11:39 AM

Contributor

5121 Points

827 Posts

### Re: Help with if statement

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)

• Edited by Ramesh T on Feb 20, 2012 11:56 AM
• Edited by Ramesh T on Feb 20, 2012 12:03 PM
• Edited by Ramesh T on Feb 20, 2012 12:06 PM
• Edited by Ramesh T on Feb 20, 2012 12:08 PM
• Edited by Ramesh T on Feb 20, 2012 12:09 PM
• Marked as answer by caponet on Feb 20, 2012 01:29 PM

Contributor

6801 Points

1059 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

• Marked as answer by caponet on Feb 20, 2012 01:29 PM

Member

4 Points

4 Posts