> .....not the least of > which being that it becomes very difficult to do anything with the > value within a query in a relational database where I would be storing > the value of "option". So instead I generally store individual columns > of type integer or number(1,0).
I think you can... using bitwise concantenation '&' - but I am way out of my depth here theoretically - seems to work empirically though! Seriously - if anyone has any light to spread on my actual understanding of this I should greatly appreciate it... My table: row | superstatus | switch_list (for reference) 1 | 1023 | 0,1,2,3,4,5,6,7,8,9 2 | 959 | 0,1,2,3,4,5,7,8,9 3 | 1019 | 0,1,3,4,5,6,7,8,9 4 | 0 | in MSSQL the queries: SELECT * FROM MyTable WHERE superstatus & power(2,6) > 0 -- returns rows 1 & 3 ie switch 6 is present SELECT * FROM MyTable WHERE superstatus & power(2,6) = 0 -- returns rows 2 & 4, ie switch 6 is not present SELECT * FROM MyTable WHERE superstatus & power(2,6) > 0 AND superstatus & power(2,2) > 0 -- returns row 1 ie switches 6 & 2 are present ... Etc. I've integrated this into a MSSQL UDF to make it a bit simpler to use; dbo.udf_IsSwitch(superstatus,6) "S. Isaac Dealey" wrote: > > > ...when you have a value eg 22 which is made up of 2+4+16 > > so you know of > > all your options valued 2,4,8,16,32 Etc only 2 and 4 and > > 16 apply. > > > I know there must be a mathematical name for this, but > > what? > > > Does anyone have some example CF code to 'decrypt' such > > numbers? > > > Are there other [simple] ways to do this to handle a large > > number of > > options (>25, so I don't start having giant numbers?) > > Something to do > > with prime numbers perhaps? > > > You can tell I'm not a mathmatician can't you! > > > THANKS! > > If you really want something like this (I generally don't), I would > look into using bitmaskread and bitmaskset... > > Start with 0 ... this gives you an integer which will have (iirc) 32 > registers for placing a bit... so you can turn any individual bit on > or off like so: > > <cfset options = 0> > > <!-- turn on the option in the first bit ---> > <cfset options = bitMaskSet(options,1,0)> > > Then to read that option: > > <cfset option1 = bitMaskRead(options,0)> > > ... the bitmask functions allow you to manipulate more than one bit at > a time, but this is probably the easiest way to handle it. > > I generally avoid using these for a host of reasons, not the least of > which being that it becomes very difficult to do anything with the > value within a query in a relational database where I would be storing > the value of "option". So instead I generally store individual columns > of type integer or number(1,0). > > p.s. I recognize the pattern you were asking for (which is different > than this bitmask solution)... in grade school I remember having to > use those values to assign display properties in GW Basic, among other > things. At the time they were dealing with extremely limited hardware > (physical ram). Imo nowadays it's always more trouble than it's worth. > > s. isaac dealey 954.927.5117 > > new epoch : isn't it time for a change? > > add features without fixtures with > the onTap open source framework > http://www.sys-con.com/story/?storyid=44477&DE=1 > http://www.sys-con.com/story/?storyid=45569&DE=1 > http://www.fusiontap.com > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Purchase from House of Fusion, a Macromedia Authorized Affiliate and support the CF community. http://www.houseoffusion.com/banners/view.cfm?bannerid=35 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:182305 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

