View previous topic :: View next topic |
Author |
Message |
ritchie
Joined: 13 Sep 2003 Posts: 87
|
Need Comments on this method? |
Posted: Mon Apr 05, 2004 5:28 pm |
|
|
Hi,
I have an application in a security system wherein I use a 2byte (16bit) data.
This 16bit corresponds to a door access wherein each bit corresponds to one door. If it is 1 u are granted access to that door otherwise if 0 no access.
What wud be a good algorithm or a snippet to read every bit of the 16bit such that we can distinguish which door are granted for a specific IDs.
Thank u. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Apr 05, 2004 5:39 pm |
|
|
I'm not sure if I understand you problem correctly, but you can use the CCS function bit_test() for checking the bits of a variable:
Quote: |
BIT_TEST( )
Syntax:
value = bit_test (var, bit)
Parameters:
var may be a 8,16 or 32 bit variable (any lvalue) bit is a number 0-31 representing a bit number, 0 is the least significant bit.
Returns:
0 or 1
Function:
Tests the specified bit (0-7,0-15 or 0-31) in the given variable. The least significant bit is 0. This function is much more efficient than, but otherwise the same as: ((var & (1<<bit)) != 0)
|
|
|
|
Al
Joined: 13 Nov 2003 Posts: 28 Location: Belfast
|
Re: Need Comments on this method? |
Posted: Tue Apr 06, 2004 5:37 am |
|
|
Hi Ritchie,
My understanding is that you would require a 16bit word to be stored for every user. You could manitain a 2-D array for this.
int16 securityDatabase[NUMBEROFUSERS][2]
This will give you a table with 2 columns - the first a 16 bit UserID and the second a the security map for that user to all the doors.
Unfortunately you would have to loop through and test each bit using the above bit test - incrementing which bit you are testing for each iteration of the loop.
I hope this helps. _________________ Alan Murray |
|
|
j11 Guest
|
|
Posted: Tue Apr 06, 2004 8:52 am |
|
|
why not make each persons code the correct 16 bit number for the doors that thay have access too. if a person has acces to all doors his code would be 65535. you could use some type of encryption scheme to make it less obvious. |
|
|
Al
Joined: 13 Nov 2003 Posts: 28 Location: Belfast
|
|
Posted: Wed Apr 07, 2004 5:24 am |
|
|
j11 wrote: | why not make each persons code the correct 16 bit number for the doors that thay have access too. if a person has acces to all doors his code would be 65535. you could use some type of encryption scheme to make it less obvious. |
The problem with this solution arises when person X has access to doors 2 and 3. Do you add the numerbs together to get 5. Then this can be mistaken for door 5.
I believe the solution is a bitmap, where bit1 represents door 1 and bit2 door2 etc. If there are more than 16 doors use 32 bits or extend table if more than 32 doors. _________________ Alan Murray |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
|
Posted: Wed Apr 07, 2004 6:56 am |
|
|
J11's idea IS a bit -map. Say you want access to doors 2 & 3 (and assume the 'first' door is #1 not #0). That persons 'code' would be (8 bit binary) 0000 0110. Yes, that = 5 but door five would be 0001 0000. One bit is set for each door and is 2^(door#-1).
- SteveS |
|
|
ritchie
Joined: 13 Sep 2003 Posts: 87
|
|
Posted: Thu Apr 08, 2004 11:43 pm |
|
|
SteveS wrote: | J11's idea IS a bit -map. Say you want access to doors 2 & 3 (and assume the 'first' door is #1 not #0). That persons 'code' would be (8 bit binary) 0000 0110. Yes, that = 5 but door five would be 0001 0000. One bit is set for each door and is 2^(door#-1).
- SteveS |
Hello SteveS!!
You're idea is great especially with the formula you provide...
Thank u... |
|
|
|