473,657 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BIT banging help

I want to store the maximum amount of permissions in a bit mask.

From what I know, I should use the C# long data type and use the
bigint in sqlserver.

How would I initialize a variable of type long to represent a 64bit
mask?

I think it is something like:

0x0............ ..0

But I am unsure as to the exact number of 0's, can someone clear this
up for me (with as much detail as possible).
Jan 17 '08 #1
9 2355
On Thu, 17 Jan 2008 11:59:58 -0800, DotNetNewbie <sn***********@ yahoo.com
wrote:
[...]
How would I initialize a variable of type long to represent a 64bit
mask?

I think it is something like:

0x0............ ..0

But I am unsure as to the exact number of 0's, can someone clear this
up for me (with as much detail as possible).
long grbitMask = 0;

You can write as many zeros in your literal as you like. The number is
still zero.

Jan 17 '08 #2

"DotNetNewb ie" <sn***********@ yahoo.comwrote in message
news:fb******** *************** ***********@q77 g2000hsh.google groups.com...
>I want to store the maximum amount of permissions in a bit mask.

From what I know, I should use the C# long data type and use the
bigint in sqlserver.

How would I initialize a variable of type long to represent a 64bit
mask?

I think it is something like:

0x0............ ..0

When entering the digits in hexadecimal (prefix 0x), every digit
represents four bits. Therefore, you would need 16 hex digits to represent a
64-bit value. However, if it is all zeroes that you want, you don't have to
write all of them. Just writing value=0 will set to zero all the bits in
value.
Jan 17 '08 #3
On Jan 17, 3:17*pm, "Alberto Poblacion" <earthling-
quitaestoparaco ntes...@poblaci on.orgwrote:
"DotNetNewb ie" <snowman908...@ yahoo.comwrote in message

news:fb******** *************** ***********@q77 g2000hsh.google groups.com...
I want to store the maximum amount of permissions in a bit mask.
From what I know, I should use the C# long data type and use the
bigint in sqlserver.
How would I initialize a variable of type long to represent a 64bit
mask?
I think it is something like:
0x0............ ..0

* * When entering the digits in hexadecimal (prefix 0x), every digit
represents four bits. Therefore, you would need 16 hex digits to representa
64-bit value. However, if it is all zeroes that you want, you don't have to
write all of them. Just writing value=0 will set to zero all the bits in
value.
I want to make an enumeration that will represent all my permission
values for each role, then I will get all the users roles and then OR
them together to get the users final permission value.

So something like:

enum Permisions : long
{
CanLogIn = 0,
CanXXXX = 0x0000000000000 001,
CanAAA = 0x0000000000000 002,
CanBBB = 0x0000000000000 004,
etc.

}

1. how many enum values can I store with a long? (which I will then
store as a bigint in sqlserver).
Jan 17 '08 #4
On Thu, 17 Jan 2008 13:23:21 -0800, DotNetNewbie <sn***********@ yahoo.com>
wrote:
[...]
1. how many enum values can I store with a long? (which I will then
store as a bigint in sqlserver).
Do you know how many bits are in a long?

Do you know how many bits it takes to store one permission flag?

You _should_ already have the answers to both of those questions. And
from those answers, the answer to "how many enum values can I store with a
long" is trivial to answer.

Pete

Jan 17 '08 #5
On Jan 17, 4:44*pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Thu, 17 Jan 2008 13:23:21 -0800, DotNetNewbie <snowman908...@ yahoo.com>*
wrote:
[...]
1. *how many enum values can I store with a long? (which I will then
store as a bigint in sqlserver).

Do you know how many bits are in a long?

Do you know how many bits it takes to store one permission flag?

You _should_ already have the answers to both of those questions. *And *
*from those answers, the answer to "how many enum values can I store with a *
long" is trivial to answer.

Pete
long is 64 bits, or 8 bytes.

I want to be able to AND and OR each permission enum value, so there
can't be any overlap.
From what I understand that I will use 1 bit per permission right?

Jan 17 '08 #6
DotNetNewbie wrote:
On Jan 17, 3:17 pm, "Alberto Poblacion" <earthling-
quitaestoparaco ntes...@poblaci on.orgwrote:
>"DotNetNewbi e" <snowman908...@ yahoo.comwrote in message

news:fb******* *************** ************@q7 7g2000hsh.googl egroups.com...
>>I want to store the maximum amount of permissions in a bit mask.
From what I know, I should use the C# long data type and use the
bigint in sqlserver.
How would I initialize a variable of type long to represent a 64bit
mask?
I think it is something like:
0x0.......... ....0
When entering the digits in hexadecimal (prefix 0x), every digit
represents four bits. Therefore, you would need 16 hex digits to represent a
64-bit value. However, if it is all zeroes that you want, you don't have to
write all of them. Just writing value=0 will set to zero all the bits in
value.

I want to make an enumeration that will represent all my permission
values for each role, then I will get all the users roles and then OR
them together to get the users final permission value.

So something like:

enum Permisions : long
{
CanLogIn = 0,
CanXXXX = 0x0000000000000 001,
CanAAA = 0x0000000000000 002,
CanBBB = 0x0000000000000 004,
etc.

}

1. how many enum values can I store with a long? (which I will then
store as a bigint in sqlserver).
You can store 64 bits if you use a ulong and bigint unsigned.
You can store 63 bits if you use a long and bigint.

You don't need to worry about setting the values - just use:

[Flags]
enum Permissions : ulong
{
CanLogIn,
CanXXXX,
CanAAA,
CanBBB
}

Alun Harford
Jan 17 '08 #7
On Thu, 17 Jan 2008 13:53:20 -0800, DotNetNewbie <sn***********@ yahoo.com>
wrote:
long is 64 bits, or 8 bytes.
Yes.
I want to be able to AND and OR each permission enum value, so there
can't be any overlap.
Yes. Obviously you cannot use the same bit for two different values.
From what I understand that I will use 1 bit per permission right?
Assuming each permission is "on" or "off", yes.
Jan 17 '08 #8
Alun Harford formulated the question :
You don't need to worry about setting the values - just use:

[Flags]
enum Permissions : ulong
{
CanLogIn,
CanXXXX,
CanAAA,
CanBBB
}

Alun Harford
No, that would still use underlying values of 0, 1, 2, 3 instead of 1,
2, 4, 8

Hans Kesting
Jan 18 '08 #9
You can do something like this

public class Permissions
{
ulong val = 0;

public enum Attr
{
CanLogIn,
CanXXXX,
CanAAA,
CanBBB
}

public Permissions (params Attr[] attr)
{
val = 0;
foreach (Attr a in attr)
val |= ( 1U << (int) a );
}

public bool IsSet(Attr a)
{
return ((val & ( 1U << (int) a )) != 0);
}

// etc
}
and then

Permissions p = new Permissions(Per missions.Attr.C anAAA,
Permissions.Att r.CanBBB);

bool b = p.IsSet(Permiss ions.Attr.CanBB B);
b = p.IsSet(Permiss ions.Attr.CanLo gIn);

Could be done better but I know C++ better than C#. Checkout [Flags] for
Attr.
"Hans Kesting" <in************ @spamgourmet.co mwrote in message
news:mn******** *************** @spamgourmet.co m:
Alun Harford formulated the question :

You don't need to worry about setting the values - just use:

[Flags]
enum Permissions : ulong
{
CanLogIn,
CanXXXX,
CanAAA,
CanBBB
}

Alun Harford


No, that would still use underlying values of 0, 1, 2, 3 instead of 1,
2, 4, 8

Hans Kesting
Jan 18 '08 #10

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

Similar topics

21
6530
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
6
4331
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
4
1362
by: SteveKlett | last post by:
I took over some code for someone here and I have a real irritating situation. There are 20 or so structs that are initialized ad I need to change some of the values of these structs based on a user defined option. So, 20 struct arrays like this: <code> typedef struct{ int a;
3
3351
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
7
5368
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
5
3260
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
8
3222
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
10
3351
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
1
6121
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
4
2164
by: TheNational22 | last post by:
I have set up PHP 5, Apache 2, and MySQL on a vista pro 64bit machine. I am using the Sams teach yourself text to set up and learn from. When i navigate to localhost and look at a html file, i see a webpage, if i look at a php script, i get nothing, just blank, and i can't even view source. I have checked and re-checked php.iini and httpd, and tried different configs I have found in other posts, nothing seems to be working, I thank you in...
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.