binary integer logic

Reply

Join Date: Aug 2006
Posts: 15
Reputation: p_eqlz_np is an unknown quantity at this point 
Solved Threads: 0
p_eqlz_np p_eqlz_np is offline Offline
Newbie Poster

binary integer logic

 
0
  #1
Aug 4th, 2006
I have a question I am hoping someone here can help me with. let's say we have a bunch of atomic groups (cannot be broken down further), i will give each of them a bit mask. we also have a bunch of users, and each one has a binary value that tells us which atomic groups the user is in. Example:

Groups
G1 - 00001 - (1)
G2 - 00010 - (2)
G3 - 00100 - (4)
G4 - 01000 - ( 8 )
G5 - 10000 - (16)

Users
U1 - 00011 - User is in groups 1 and 2
U2 - 01100 - in groups 3 and 4
U3 - 00010 - in group 2
U4 - 10000 - in group 5
U5 - 01011 - in groups 1, 2, 4

Now we also have groups of groups which are composed of some basic formula. For Example:

Groups of Groups
GG1 - (G1 && G2) || G3
GG2 - (G2 || G3) && (G1 && G4)
GG3 - (G1 && (G2 || G3)) || G5

Now I want to be able to determine all the users that satisfy the conditions for GG1, GG2 and GG3. So based on the above examples, we have:

Users in GG1: U1, U2, U5
Users in GG2: U5
Users in GG3: U1, U4, U5

How can I algorithmically determine this? The groups, users and groups of groups are stored as you see above. Given a user's binary value I need to be able to "plug" it into the GG formula and determine if it is true or not. Do I have to break apart the GG formulas and dynamically map them into if statements? I am hoping for an easier way since they could possibly get complicated.

Thanks for any help.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: binary integer logic

 
0
  #2
Aug 4th, 2006
You can make a mask representing what users are in each group: for example, for G1, that would be 10001, for G2, that would be 10101, and so on. Then combine these masks using regular bitwise operations.
Last edited by Rashakil Fol; Aug 4th, 2006 at 8:24 am.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 15
Reputation: p_eqlz_np is an unknown quantity at this point 
Solved Threads: 0
p_eqlz_np p_eqlz_np is offline Offline
Newbie Poster

Re: binary integer logic

 
0
  #3
Aug 4th, 2006
I'm not sure I understand what you mean. So in addition to the group's mask, I have another binary value that represents which users are in the group? And then what will I get by combining them?

Keep in mind that I should be able to have hundreds of groups and groups of groups, and thousands of users so I need to be able to store these large values and do operations on them without much of a problem. If I have a thousand users, that's a thousand bit integer right there.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: binary integer logic

 
0
  #4
Aug 4th, 2006
If these are actual formulas:
Originally Posted by p_eqlz_np
Groups of Groups
GG1 - (G1 && G2) || G3
GG2 - (G2 || G3) && (G1 && G4)
GG3 - (G1 && (G2 || G3)) || G5
then
GG1 = G3
GG2 = 0
GG3 = G5


Originally Posted by p_eqlz_np
Now I want to be able to determine all the users that satisfy the conditions for GG1, GG2 and GG3. So based on the above examples, we have:

Users in GG1: U1, U2, U5
Users in GG2: U5
Users in GG3: U1, U4, U5

How can I algorithmically determine this?
AND the user with the GGroup. If != 0, user is in the group.
Last edited by WaltP; Aug 4th, 2006 at 3:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 15
Reputation: p_eqlz_np is an unknown quantity at this point 
Solved Threads: 0
p_eqlz_np p_eqlz_np is offline Offline
Newbie Poster

Re: binary integer logic

 
0
  #5
Aug 4th, 2006
Originally Posted by WaltP
If these are actual formulas:
then
GG1 = G3
GG2 = 0
GG3 = G5


AND the user with the GGroup. If != 0, user is in the group.
Sorry, I guess I wasn't clear. You can't just simplify the GG "formulas" like that, they are not actually formulas.

GG1 - (G1 && G2) || G3

Note that the && and || are NOT bit operators.. they are the logical and/or operators. So for example, GG1 contains ALL users that are in BOTH G1 and G2, OR just in G3. So in the end it comes down to true/false. Like U1 who is in G1 and G2, the above "formula" would be

((T && T) || F) which is of course T
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: binary integer logic

 
0
  #6
Aug 4th, 2006
That makes no sense.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 15
Reputation: p_eqlz_np is an unknown quantity at this point 
Solved Threads: 0
p_eqlz_np p_eqlz_np is offline Offline
Newbie Poster

Re: binary integer logic

 
0
  #7
Aug 4th, 2006
no reason to be sad! i'm terrible at explaining things. i would be the worst teacher in the world.. hehe..

anyway maybe this will help, if you put the GG rules into words.

So first I said GG1 = (G1 AND G2) OR G3. sorry for making it so formula-ish even though its not really one.

in words: the users in GG1 are those that are either BOTH in G1 and G2 OR just in G3.

so if U1 is in (G1,G2) and U2 is in (G3), both U1 and U2 would be part of GG1. hope i am making sense now
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: binary integer logic

 
0
  #8
Aug 4th, 2006
Originally Posted by p_eqlz_np
no reason to be sad! i'm terrible at explaining things. i would be the worst teacher in the world.. hehe..

anyway maybe this will help, if you put the GG rules into words.

So first I said GG1 = (G1 AND G2) OR G3. sorry for making it so formula-ish even though its not really one.

in words: the users in GG1 are those that are either BOTH in G1 and G2 OR just in G3.

so if U1 is in (G1,G2) and U2 is in (G3), both U1 and U2 would be part of GG1. hope i am making sense now
Ok that still don't make any sense.

Ok let's keep it simple. Let's say you have some variables G1,G2,G3...GN.

These variables (GN) can take two forms, 0 or 1 true or false.

So essentially you are saying:

Giving various boolean formulas:

 (G1 && G2) || G3 
(G2 || G3) && (G1 && G4) 
(G1 && (G2 || G3)) || G5

Determine the final result, i.e it would each expression be either be true or false?

And you want a way to code the expressions dynamically (like say at the command line) rather than having to list a whole bunch of if / and conditions?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 15
Reputation: p_eqlz_np is an unknown quantity at this point 
Solved Threads: 0
p_eqlz_np p_eqlz_np is offline Offline
Newbie Poster

Re: binary integer logic

 
0
  #9
Aug 4th, 2006
Originally Posted by iamthwee
Ok that still don't make any sense.

Ok let's keep it simple. Let's say you have some variables G1,G2,G3...GN.

These variables (GN) can take two forms, 0 or 1 true or false.

So essentially you are saying:

Giving various boolean formulas:

 (G1 && G2) || G3 
(G2 || G3) && (G1 && G4) 
(G1 && (G2 || G3)) || G5
Determine the final result, i.e it would each expression be either be true or false?

And you want a way to code the expressions dynamically (like say at the command line) rather than having to list a whole bunch of if / and conditions?
ah.. so the variables (G1..Gn) as you said are more than just true/false. they are bit masks.. so the masks are:
G1: 0001
G2: 0010
G3: 0100
G4: 1000

and then given a user's mask (ie 0110, which states that the user is in G2 and G3 by ANDing against the G2 and G3 bit masks), then yes, i want to determine the final result (true/false) of the expressions. and by dynamically, i mean these expressions are not hard coded anywhere. they are stored somewhere of course, but not in the actual code. given a user's mask and the expression i should be able to call some function which will return true or false.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: binary integer logic

 
0
  #10
Aug 4th, 2006
Originally Posted by p_eqlz_np
ah.. so the variables (G1..Gn) as you said are more than just true/false. they are bit masks.. so the masks are:
G1: 0001
G2: 0010
G3: 0100
G4: 1000

and then given a user's mask (ie 0110, which states that the user is in G2 and G3 by ANDing against the G2 and G3 bit masks), then yes, i want to determine the final result (true/false) of the expressions. and by dynamically, i mean these expressions are not hard coded anywhere. they are stored somewhere of course, but not in the actual code. given a user's mask and the expression i should be able to call some function which will return true or false.
I'm still struggling to understand, maybe it's just me, but your first example is throwing me of.

Anyway, regardless of GN being just 0 or 1 or a string of zeros and ones, the idea should still be the same.

What you have to do is create an equation parser to handle any type expression. So that your program can handle it rather than just hard coded expressions.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the IT Professionals' Lounge Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC