| | |
binary integer logic
![]() |
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
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.
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.
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.
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
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.
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.
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.
•
•
•
•
Originally Posted by p_eqlz_np
Groups of Groups
GG1 - (G1 && G2) || G3
GG2 - (G2 || G3) && (G1 && G4)
GG3 - (G1 && (G2 || G3)) || G5
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?
Last edited by WaltP; Aug 4th, 2006 at 3:27 pm.
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
•
•
•
•
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.
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
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
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
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
•
•
•
•
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 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*
•
•
Join Date: Aug 2006
Posts: 15
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by iamthwee
Ok that still don't make any sense.
Ok let's keep it simple. Let's say you have some variablesG1,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:
Determine the final result, i.e it would each expression be either be true or false?(G1 && G2) || G3 (G2 || G3) && (G1 && G4) (G1 && (G2 || G3)) || G5
And you want a way to code the expressions dynamically (like say at the command line) rather than having to list a whole bunch ofif / andconditions?
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.
•
•
•
•
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.
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*
![]() |
Similar Threads
- binary integer logic (Computer Science)
Other Threads in the IT Professionals' Lounge Forum
- Previous Thread: An Invitation
- Next Thread: Parental Control on Mac OSX
| Thread Tools | Search this Thread |
1gbit advertising advice amazon answers archive british broadband business businessprocesses career carrier censorship cern china cio collectiveintelligence connectivity consumer consumers corporateearnings datatransfer debtcollectors dictionary digg digital ebay ecommerce email employment environment facebook food government grid high-definition hottub infodelivery infotech intel internet interview ipod isp japan kindle lhc library malware marketing mit moonfruit news onlineshopping piracy piratebay pope porn program questions r&d religion remoteworking research retail security sex shopping simple skype smallbusiness smb sms socialmedia socialnetworking software softwareengineer spam speed spending startrek statistics stocks study stumbleupon survey tabletpc technology touch-screen touchscreen twitter uk videoinprint voips web webdeveloper windows words






