Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 20, 2012 01:30 PM by caponet
Member
4 Points
4 Posts
Feb 20, 2012 11:35 AM|LINK
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
5121 Points
827 Posts
Feb 20, 2012 11:55 AM|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)
6801 Points
1059 Posts
Feb 20, 2012 11:58 AM|LINK
The result has to do with binary "AND"
for the first case:
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:
Binary of 512 : 00000001000000000
when you "AND" this, you get "00000000000000000" not equal to binary of 512 so you get false.
Feb 20, 2012 01:30 PM|LINK
Thank you it makes sense
caponet
Member
4 Points
4 Posts
Help with if statement
Feb 20, 2012 11:35 AM|LINK
Hi,
Could someone help me to understand the logic behind this if statement?
Why the following statement returns true
and the following one returns false
Thank you
Ramesh T
Contributor
5121 Points
827 Posts
Re: Help with if statement
Feb 20, 2012 11:55 AM|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)
sandeepmitta...
Contributor
6801 Points
1059 Posts
Re: Help with if statement
Feb 20, 2012 11:58 AM|LINK
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
caponet
Member
4 Points
4 Posts
Re: Help with if statement
Feb 20, 2012 01:30 PM|LINK
Thank you it makes sense