|
-
Apr 22nd, 2003, 01:16 AM
#1
Thread Starter
Hyperactive Member
suggestions needed
I am creating a virtual cabinet in which I have many files say thousands. Each file can belong to one or more categories that is why In data base there should be a Bit mask through which the file can be retrieved. That mask should be a 32 bit binary number.
There are levels of the categories. All major categories have sub categories and those sub categories can also have sub sub categories. A file can belong to a sub category and it can also then belong to a major category. like if there is a major category A which have sub category B and Category B have a sub sub category C and there is another major category X which have a sub category Y and there is a file Z which belongs to the category Y and can belongs to category B.
Each category and sub category has also a bit mask ( 32 bit number) .As it is a 32 bit binary number there are 4 chunks of 8 bits . first chunk is for the major category second chunk of 8 bit is for sub category and 3rd chunk is for sub sub category and 4th one is for sub sub sub category . for the above example the bit mask would be
Category A = 00000000 00000000 00000000 00000001
Category B = 00000000 00000000 00000001 00000001
Category C = 00000000 00000001 00000001 00000001
Category X = 00000000 00000000 00000000 00000010
Category Y = 00000000 00000000 00000001 00000010
So from the mask C we can easily see that it belongs to a sub catogry B and it has a major category A
Now I would like to know that what would be a the bit mask of the file Z. which belongs to both the Y and B catgory.so that I can depict from where it belongs .
any suggestions would be appriciated
-
Apr 22nd, 2003, 02:51 AM
#2
Retired VBF Adm1nistrator
00000000 00000000 00000001 00000011
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 22nd, 2003, 03:47 AM
#3
Thread Starter
Hyperactive Member
?
how did you make that. i mean which logic you used to come up with this number
-
Apr 22nd, 2003, 03:49 AM
#4
Retired VBF Adm1nistrator
To add bitmasks together you Or the numbers.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 22nd, 2003, 03:59 AM
#5
Lively Member
Category A = 00000000 00000000 00000000 00000001
Category B = 00000000 00000000 00000001 00000001
Category C = 00000000 00000001 00000001 00000001
is this right ?
i would have thought that the mask C would have looked like
00000000 00000000 00000001 00000001 ????
-
Apr 22nd, 2003, 04:29 AM
#6
Thread Starter
Hyperactive Member
Yes, but if i OR them then it would become much confusing. like in this case
00000000 00000000 00000001 00000011
this bit mask can also depict that this is a sub catogorey of third major category... got it or not .. so then how would i diffrentiate that ?
-
Apr 22nd, 2003, 04:34 AM
#7
Retired VBF Adm1nistrator
Ok. What you would want to do is something like this :
CatA : 00000001
CatB : 00000010
CatC : 00000100
CatD : 00001000
CatE : 00010000
CatF : 00100000
CatG : 01000000
CatH : 10000000
So by Or'ing the numbers together you can specify that an object is a member of any category A - H, and combinations too.
Eg: An item is a member of CatA and CatB and CatG :
01000011
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 22nd, 2003, 04:39 AM
#8
Thread Starter
Hyperactive Member
ok then ?
then how would i decrypt this OR thingy
-
Apr 22nd, 2003, 04:56 AM
#9
Retired VBF Adm1nistrator
You AND a field against it, and if you get the same value back, then that value has been set.
Eg :
Item is in CatA and CatF :
Bitfield : 00100001
To check if it is a member of CatB :
00000010 = 00100001 And 00000010
The above expression would return False.
But if you wanted to check if it was a member of CatA :
00000001 = 00100001 And 00000010
The above expression would be True.
(00100001 And 00000010 would return 00000001)
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 22nd, 2003, 05:15 AM
#10
Thread Starter
Hyperactive Member
but
this things would only applicable if we have a file belongs to only two major categories .. but what here a file can alos belong to a sub sub category . so how would this method apply in that case.
please refer to my first post for the sub sub categories
-
Apr 22nd, 2003, 05:16 AM
#11
Retired VBF Adm1nistrator
Then you would maintain a second bitfield, and use the same technique again.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|