944,083 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Aug 4th, 2006
0

binary integer logic

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
p_eqlz_np is offline Offline
15 posts
since Aug 2006
Aug 4th, 2006
1

Re: binary integer logic

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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Aug 4th, 2006
0

Re: binary integer logic

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
p_eqlz_np is offline Offline
15 posts
since Aug 2006
Aug 4th, 2006
0

Re: binary integer logic

If these are actual formulas:
Quote 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


Quote 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.
Moderator
Reputation Points: 3281
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Aug 4th, 2006
0

Re: binary integer logic

Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
p_eqlz_np is offline Offline
15 posts
since Aug 2006
Aug 4th, 2006
0

Re: binary integer logic

That makes no sense.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 4th, 2006
0

Re: binary integer logic

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
p_eqlz_np is offline Offline
15 posts
since Aug 2006
Aug 4th, 2006
0

Re: binary integer logic

Quote 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?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 4th, 2006
0

Re: binary integer logic

Quote 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
p_eqlz_np is offline Offline
15 posts
since Aug 2006
Aug 4th, 2006
0

Re: binary integer logic

Quote 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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in IT Professionals' Lounge Forum Timeline: An Invitation
Next Thread in IT Professionals' Lounge Forum Timeline: A Let-Up On The Beat-Down





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC