How to assign members for shop in a inventory control system

User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

Re: How to assign members for shop in a inventory control system

Post by Herath » Wed May 30, 2012 2:16 pm

use bitwise 'and' operator.
if(100010&10) (it is the second shop)

[ Post made via Mobile Device ] Image
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: How to assign members for shop in a inventory control system

Post by Saman » Wed May 30, 2012 2:56 pm

Exactly as Herath stated, you need to use bit wise AND (&) and OR (|) operators to filter out releveant information from that.

I'll give you an example. Say that one user is trying to access 1st store while his access signature is 34. As Herath stated, you check if (signature & 1) is true or false. If true, that means this user has access, if not, user doesn't have access.

So the common form is (signature & x) where x is the bit-wise location of the store as below.
0000 0000 0000 0001 - 1st store
0000 0000 0000 0010 - 2nd store
0000 0000 0000 0100 - 3rd store
0000 0000 0000 1000 - 4th store
0000 0000 0001 0000 - 5th store
....
...

Computationally, you can check it as if (signature & (1 << (store_no - 1))).
User avatar
viddz
Sergeant Major
Sergeant Major
Posts: 45
Joined: Fri Aug 26, 2011 6:06 am
Location: Colombo

Re: How to assign members for shop in a inventory control system

Post by viddz » Wed May 30, 2012 10:12 pm

Thank you guys I got it. :D
Post Reply

Return to “PHP & MySQL”