473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

flag operator questions

I am using flag as the identifier for various security settings. For
instance:

Public Enum SecurityEnum
Read=0
Write=1
Delete=2
...
End Enum

I have a few questions:
1). If I want to group a number of these rights into a role, should I
determine the xor result of all the rights that i need? or always xor the
rights?
2). What type of database field should i use for storage? Byte? What
size field?
3). Is there an easy way to determine the value of all bits being turned
on?
4). Does it matter if i define the values in the enum using 1,2,4 or
&h1,&h2,&h4?
5). What is the right 'numbering' for each successive bit? Powers of 2,
correct? In hex, would that be &h0,&h1,&h2,&h4,&h8,&h16...?
6). Can someone suggest a primer on using flags?

Thanks in advance,

Craig Buchanan
Nov 20 '05 #1
1 2116
Craig,
1). If I want to group a number of these rights into a role, should I
determine the xor result of all the rights that i need? or always xor the
rights? Huh? Do you mean "add" the rights together, you would use OR, you would use
Xor to toggle a right.

Dim rights As Security = Security.Read Or Security.Write

rights = rights Xor Security.Delete ' add Delete

rights = rights Xor Security.Delete ' remove Delete
2). What type of database field should i use for storage? Byte? What
size field? I would use a Integer, unless I gave the enum a smaller type. Remember you
can define the Enum to the size you want using As Byte, Short, Integer, or
Long on the definition.

Public Enum Security As Byte
3). Is there an easy way to determine the value of all bits being turned on? I normally use the And operator

Dim mask As Security = Security.Read Or Security.Write
If (rights And mask) = mask Then
4). Does it matter if i define the values in the enum using 1,2,4 or
&h1,&h2,&h4? Only when you get to 10 ;-) In VB.NET 2003 I sometimes use the Left Shift
operator

<Flags()> _ Public Enum Security None = 0 Read= 1 << 0
Write= 1 << 1
Delete= 1 << 2 Browse = 1 << 3
Update = 1 << 4 ...
End Enum 5). What is the right 'numbering' for each successive bit? Powers of 2, correct? In hex, would that be &h0,&h1,&h2,&h4,&h8,&h16...? Powers of 2 starting with 1 as you cannot test the value 0 as being set, I
normally reserve it for "None".
6). Can someone suggest a primer on using flags? Don't know of any specific primers per se, however the following links may
be useful:

http://msdn.microsoft.com/library/de...Guidelines.asp

Hope this helps
Jay

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:Oq**************@TK2MSFTNGP10.phx.gbl... I am using flag as the identifier for various security settings. For
instance:

Public Enum SecurityEnum
Read=0
Write=1
Delete=2
...
End Enum

I have a few questions:
1). If I want to group a number of these rights into a role, should I
determine the xor result of all the rights that i need? or always xor the
rights?
2). What type of database field should i use for storage? Byte? What
size field?
3). Is there an easy way to determine the value of all bits being turned on?
4). Does it matter if i define the values in the enum using 1,2,4 or
&h1,&h2,&h4?
5). What is the right 'numbering' for each successive bit? Powers of 2, correct? In hex, would that be &h0,&h1,&h2,&h4,&h8,&h16...?
6). Can someone suggest a primer on using flags?

Thanks in advance,

Craig Buchanan

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
2
by: victor75040 | last post by:
Before you all start flaming me, I am not a student and this is not for any homework. Just someone learing c++ on their own. I am now up to the chapter in my book that describes operator...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
3
by: CoolPint | last post by:
After upgrading to gcc 3.4.2 from gcc 3.2.3, I got compiler errors that I could not figure out. After reading other postings, I learned that my coding was not compliant to the standard in the first...
19
by: jacob navia | last post by:
C++ introduced an interesting feature (among others): operator overloading. The idea is to build a mechanism for the user defining its own number types and the operations to be done with them. ...
1
by: chetan | last post by:
Hi All ! Are int,char,long,..etc. classes in c++ ? And if so, how can i overload new and del operator for the objects of this classes ? That is i want to overload new int, new char and so on......
2
by: Mr Dyl | last post by:
I'm having a few issues porting Windows code to Linux (VS.Net 2003 to GCC 4.0.1). So this probably has something to do with VS not catching non-compliant code. I'd like to simplify this problem,...
18
by: Ranganath | last post by:
Why is throw keyword considered as an operator?
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.