|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
to represent when something is in use?
with an unsigned long that is 64bits I can have 64 flags. But I need more flags, around 140 flags. what can I do? Does anyone have any ideas? |
|
#2
|
|||
|
|||
|
How you calculate that 64 bit represents 64 flags? What is the mathematics?
If you are talking about flags, 64 bit should represent 2^64 different flags. |
|
#3
|
|||
|
|||
|
ok, i'm not too sure. I'm new to this bitwise operations.
well you'd have your flags ulong FLAG_INVALID = 1; ulong FLAG_NUMBER = 2; ulong FLAG_NUM_ALPHA = 4; ulong FLAG_NUM_ALPHA_WORD = 8; ulong FLAG_SUB_BUILDING = 16; ulong FLAG_POST_USED = 32; ulong FLAG_POST_TYPE = 64; ulong STATE_1 = 128; ulong STATE_2 = 256; ulong STATE_3 = 512; ulong STATE_4 = 1024; ulong STATE_5 = 2048; ulong STATE_6 = 4096; ulong STATE_7 = 8192; ulong STATE_8 = 16384; ulong STATE_9 = 32768; ulong STATE_10 = 65536; and ba da di da di da.... ulong ulStringAttributes = 0 // no flags set ulStringAttributes = ulStringAttributes | FLAG_INVALID; ulStringAttributes = ulStringAttributes | FLAG_NUM_ALPHA; ======== ulStringAttributes -> (61 Zeros)101 long is 64bits in C# no? I thought thats how it works no? So I thought it ment you could only have 64 flags? I'm probably wrong, don't really know to be honest |
|
#4
|
|||
|
|||
|
Well, I am not sure what you are trying to do in your code.
However, its a common programming practice, to determine the specific bit in a data by shifting data (to left or to right) and masking the appropriate bit. regards, |
|
#5
|
|||
|
|||
|
this is what i'm doing
the "Using bitwise operations to implement flags" section http://www.divnull.com/lward/person...ng/bitwise.html so I guess that with a long I can only implement 64 flags. But I need over 100 flags |
|
#6
|
|||
|
|||
|
Well, If your data is 64 bit long then you need 64 diff flags, in your case 1,2, 4, 8 etc.
But if you need 100 diff flags (with only 1 bit set in each) for some reason, of course there is no staright forward way, since no standard data types DO NOT support 100 bits of data. So you have to implement an algorithm to do so, which is subtle a practice of computer science students in their Data Structure courses in the universities. But, would you please explain me more why you need 100 diff flags, I mean what is the purpose, if you do not like to post the problem, if you like you can PM me. regards |
|
#7
|
|||
|
|||
|
Could all the flags potentially be set for one thing or could they be divided up into sets?
If different groups of them relate to different things then you can reuse the values. Using the example already posted have one set of values for the constants beginning FLAG_ and use the same values for the ones beginning STATE_. Obviously this doesn't work if FLAG_ and STATE_ can apply to the same thing but if not this should solve your problem. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Is there anything else other than bitwise flags |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|