I have a table of Users that includes a bitmask of roles that the user belongs to. I'd like to select users that belong to one or more of the roles in a bitmask value. For example:
select *
from [User]
where UserRolesBitmask | 22 = 22
This selects all users that have the roles '2', '4' or '16' in their bitmask. Is this possible to e...
Is there a way of comparing two bitmasks in Transact-SQL to see if any of the bits match? I've got a User table with a bitmask for all the roles the user belongs to, and I'd like to select all the users that have any of the roles in the supplied bitmask. So using the data below, a roles bitmask of 6 (designer+programmer) should select Da...
There's a common way to store multiple values in one variable, by using a bitmask. For example, if a user has read, write and execute privileges on an item, that can be converted to a single number by saying read = 4 (2^2), write = 2 (2^1), execute = 1 (2^0) and then add them together to get 7.
I use this technique in several web applic...
I'd like to find a way to do a SQL query that will calculate the cidr (bit representation) of a subnet mask stored in the database. So for example, I've got either 255.255.255.0 or its decimal value (4294967040) stored in the database. I'd like to do a select and get back /24 representation via the query.
I've done things like the fol...
Hello,
I am trying to store a large amount of boolean information that is determined at run-time. I was wondering what the best method might be.
I have currently been trying to allocate the memory using:
pStatus = malloc((<number of data points>/8) + 1);
thinking that this will give me enough bits to work with. I could then refer...
I'm writing a unit test for a method that packs boolean values into a byte. The various bit locations are determined by the value of an enum, which only has 5 values right now, but it's conceivable (though extremely unlikely) that this number could go to 9.
I'd like a simple test along the lines of:
private byte m_myNum;
enum MyEnum {...
I am running through a memory block of binary data byte-wise.
Currently I am doing something like this:
for (i = 0; i < data->Count; i++)
{
byte = &data->Data[i];
((*byte & Masks[0]) == Masks[0]) ? Stats.FreqOf1++; // syntax incorrect but you get the point.
((*byte & Masks[1]) == Masks[1]) ? Stats.FreqOf1++;
((*byte ...
Something like
SELECT COUNT(*) AS c FROM BANS WHERE typeid=6 AND (SELECT ipaddr,cidr FROM BANS) MATCH AGAINST 'this_ip';
So you don't first fetch all records from DB and then match them one-by one.
If c > 0 then were matched.
BANS table:
id int auto incr PK
typeid TINYINT (1=hostname, 4=ipv4, 6=ipv6)
ipaddr BINARY(128)
cidr INT
...
Hello,
Is there a simple way to convert a bitmask in to an array index?
ie. If i've got an enum
a = 0x01,
b = 0x02,
c = 0x04,
d = 0x08,
e = 0x10,
etc
and I want to store releated data in an array, is there a simple way such that i can convert a to 0, b to 1, c to 2. etc?
Many thanks
...
Is there any advantage of using int vs varbinary for storing bit masks in terms of performance or flexibility.
For my purposes, I will always be doing reads on these bit masks (no writes or updates).
...
Duplicate:
Best algorithm to count the number of set bits in a 32-bit integer?
Suppose you have a number. Is there any way to count the bits which equals to 1 in binary representation of that number, not using iteration? I mean, is there any way to do it in constant time using some bitwise operators and masks. I need solution whi...
I have a very large set of permissions in my application that I represent with a Flags enumeration. It is quickly approaching the practical upper bound of the long data type. And I am forced to come up with a strategy to transition to a different structure soon. Now, I could break this list down into smaller pieces, however, this is a...
I'm trying to take a 16 bit unsigned integer from a structure, mask the first 8 bits of it, and use it as an index to an array with the function analogWrite which takes the output pin on the Arduino and the output byte as arguments. The code in question looks something like this: analogWrite(outputPin, my_array[myStructure->data & 0xFF0...
inputs:
arbitrary bitset, e.g. bit positions 012345
arbitrary bit mask, e.g. (x=1) xx0x0x
output:
xx0x1x2345
That is, I want the first bit of the bitset to be placed in the first 0 of the mask. Likewise, the second bit is placed in the second 0 of the mask.
example:
mask = 1001001
bits = 1101
result = 1111011
I know that this ...
I am working on a user-role / permission system in PHP for a script.
Below is a code using a bitmask method for permissions that I found on phpbuilder.com.
Below that part is a much simpler version w3hich could do basicly the same thing without the bit part.
Many people have recommended using bit operators and such for settings and ...
for (unsigned int i = 1; i <= 100; i++) {
if (i & 0x00000001) {
std::cout << i<<",";
}
}
why does (and how): if( i & 0x00000001 ) figure out the odd number?
...
I am reading a binary file that has values stored in bit masks, both 1 Byte bit masks and 2 Byte bit masks. Each bit in the masks act as a switch that indicates where an Event has transpired.
Example of 1 Byte mask:
00000101
Indicates that Event one and Event
3 has transpired.
Example of Enum
public enum MyEnum
{
...
In my stored procedure I need a single parameter that will give me a potential of 3 values.
So I can do something like:
@p1 <-- my parameter
IF (@p1 ???) -- include users
SELECT * FROM USERS
IF (@p1 ???) -- include employees
SELECT * FROM employees
IF (@p1 ???) -- iclude customers
SELECT * FROM CUSTOMERS
I am gues...
Hi,
My object Item has several binary states which can be combined
bool CanBeSold;
bool CanBeBought;
bool CanBeExchanged;
I need to store current combination of values into one variable. The reason
is that I need to store this value in DB. In C++ I would create a bit-mask
where one state occupies some bit. Is it good practice in .NE...
This is a part of a plt-scheme wrapper library:
(define InputMask
(_bitmask '(NoEventMask = #x00000000
KeyPressMask = #x00000001
KeyReleaseMask = #x00000002
...
OwnerGrabButtonMask = #x01000000)
_long))
The thing is I cant figure out ho...