General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 14th, 2003, 05:39 AM
thomaskeegan thomaskeegan is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 15 thomaskeegan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Is there anything else other than bitwise flags

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?

Reply With Quote
  #2  
Old July 14th, 2003, 09:14 AM
iahmed iahmed is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: USA
Posts: 171 iahmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 58 sec
Reputation Power: 6
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.

Reply With Quote
  #3  
Old July 14th, 2003, 09:26 AM
thomaskeegan thomaskeegan is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 15 thomaskeegan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old July 14th, 2003, 09:52 AM
iahmed iahmed is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: USA
Posts: 171 iahmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 58 sec
Reputation Power: 6
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,

Reply With Quote
  #5  
Old July 14th, 2003, 09:56 AM
thomaskeegan thomaskeegan is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 15 thomaskeegan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #6  
Old July 14th, 2003, 10:49 AM
iahmed iahmed is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: USA
Posts: 171 iahmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 58 sec
Reputation Power: 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

Reply With Quote
  #7  
Old July 22nd, 2003, 11:03 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Is there anything else other than bitwise flags


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT