CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Need Comments on this method?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ritchie



Joined: 13 Sep 2003
Posts: 87

View user's profile Send private message

Need Comments on this method?
PostPosted: Mon Apr 05, 2004 5:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 05, 2004 5:39 pm     Reply with quote

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

View user's profile Send private message

Re: Need Comments on this method?
PostPosted: Tue Apr 06, 2004 5:37 am     Reply with quote

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







PostPosted: Tue Apr 06, 2004 8:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 5:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 6:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 08, 2004 11:43 pm     Reply with quote

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...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group