If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > How to compare this ? HELP !!!!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-03, 12:21
edmun3 edmun3 is offline
Registered User
 
Join Date: Sep 2001
Posts: 46
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.

Thanks in advanced.
Reply With Quote
  #2 (permalink)  
Old 01-13-03, 12:38
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: How to compare this ? HELP !!!!!

Quote:
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.

Thanks in advanced.
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!)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 01-13-03, 13:45
edmun3 edmun3 is offline
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
=====================
Reply With Quote
  #4 (permalink)  
Old 01-14-03, 05:38
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
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
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On