# Thread: How to compare this ? HELP !!!!!

1. Registered User
Join Date
Sep 2001
Posts
46

## Unanswered: How to compare this ? HELP !!!!!

I am now doing one small project [Laboratory Information System] and facing this math's problem...ummm too long away from school and forgot all this...

ObjectA = 111000111 <----> First Object
ObjectB = 000110000
ObjectC = 100000000

ObjectA is the main value ,ObjectB and ObjectC is selectable.
When I compare those Object or few Objects , never to have 1's occur at the same position.Example :

0011
1100 give 1111 so no error and ASP script will be continue to next session.

BUT if

0011
1110 then will give error code because this 2 object at the 3rd position with 1.

So If ObjectA compare with Object B
ObjectA = 111000111 <----> First Object
ObjectB = 000110000
==============
111110111 <--- No error

But If
ObjectA = 111000111 <----> First Object
ObjectC = 100000000
===============
1011000111 < --- error

Can someone teach me how can I know that if those 2 object when compare, how the result value able to let me know rhere is error and which position of the 1's happen.

2. Moderator.
Join Date
Sep 2002
Location
UK
Posts
5,171

## Re: How to compare this ? HELP !!!!!

Originally posted by edmun3
I am now doing one small project [Laboratory Information System] and facing this math's problem...ummm too long away from school and forgot all this...

ObjectA = 111000111 <----> First Object
ObjectB = 000110000
ObjectC = 100000000

ObjectA is the main value ,ObjectB and ObjectC is selectable.
When I compare those Object or few Objects , never to have 1's occur at the same position.Example :

0011
1100 give 1111 so no error and ASP script will be continue to next session.

BUT if

0011
1110 then will give error code because this 2 object at the 3rd position with 1.

So If ObjectA compare with Object B
ObjectA = 111000111 <----> First Object
ObjectB = 000110000
==============
111110111 <--- No error

But If
ObjectA = 111000111 <----> First Object
ObjectC = 100000000
===============
1011000111 < --- error

Can someone teach me how can I know that if those 2 object when compare, how the result value able to let me know rhere is error and which position of the 1's happen.

You need to do a logical AND:

111000111 AND 000110000 = 000000000

111000111 AND 100000000 = 100000000

So if the AND result = 0 you are OK

One way to then see which bits are set would be:

result = 111000111 AND 100000001

If result AND 100000000 > 0 then
/* bit 1 is set */
end if
If result AND 010000000 > 0 then
/* bit 2 is set */
end if
... etc.

Of course, you could do that in a loop something like:

FOR i = 1 TO 9 DO
isset(10-i) = result AND 2 ** i
END DO

(Apologies for poor pseudo-VB syntax!)

3. Registered User
Join Date
Sep 2001
Posts
46
Thanks for your explaination andrewst,the first problem[How to find out there is error object] solved.

The second one unsolved yet because I have > 400 1's to compare !!!!!!

For the looping process , I am too dump to understand it.Can you explain more further ,Dear Andrewst
====================
FOR i = 1 TO 9 DO
isset(10-i) = result AND 2 ** i
END DO
=====================

4. Moderator.
Join Date
Sep 2002
Location
UK
Posts
5,171
Originally posted by edmun3
Thanks for your explaination andrewst,the first problem[How to find out there is error object] solved.

The second one unsolved yet because I have > 400 1's to compare !!!!!!

For the looping process , I am too dump to understand it.Can you explain more further ,Dear Andrewst
====================
FOR i = 1 TO 9 DO
isset(10-i) = result AND 2 ** i
END DO
=====================
OK, I'm not sure if I used the correct syntax for VB, but what I was doing was obtaining powers of 2 from 1 to 9, using the syntax 2**i to mean (2 to the power of i) - ** is the power operator in some languages.
So:
2**1 = 2 = 000000010
2**2 = 4 = 000000100
2**3 = 8 = 000001000
etc.

I now see that I missed 2**0 = 1 = 000000001 ! So my code should have been:
FOR i = 0 TO 8 DO
isset(9-i) = result AND 2 ** i
END DO

So what it does is:
1st loop iteration: sets isset(9) = result AND 000000001
2nd loop iteration: sets isset(8) = result AND 000000010
3rd loop iteration: sets isset(7) = result AND 000000100
...
9th loop iteration: sets isset(1) = result AND 100000000

The "isset" array then shows which bits were 1/0 in result: if isset(i) = 0 then the ith bit was 0, else it was 1

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•