OK, thanks very much, I think I have a solution, though I still don't
know what this is called, or really what the bitand() function is doing
(any pointers to a -simple- explanation of the bitxx functions?)
Consider the following code. It seems to work:
<CFSET mylistOfOn = "">
<!--- create a list of 'on switches' of a random length between 1 & 30
--->
<CFSET len = randrange(1,30)>
<CFLOOP CONDITION="listlen(mylistOfOn) lte len">
<CFSET xnum = randrange(0,30)>
<CFIF listfind(mylistOfOn,xnum) eq false>
<CFSET mylistOfOn = listappend(mylistOfOn,xnum)>
</CFIF>
</CFLOOP>
<!--- generate the number --->
<CFSET num = 0>
<CFLOOP LIST="#mylistOfOn#" INDEX="idx">
<CFSET num = num + (2^idx)>
</CFLOOP>
<CFOUTPUT>List of 'on switches': #mylistOfOn#<BR>
Transposed to the single number: #num#</CFOUTPUT><BR>
<!--- test which switch is on --->
<BR> <BR>
Test the number<BR>
<CFLOOP FROM="0" TO="30" INDEX="idx">
<CFSET z = 2^idx>
<CFOUTPUT>
#idx#: <CFIF bitand(z,num) gt 0>yes<CFELSE>no</CFIF> [#z#]<BR>
</CFOUTPUT>
</CFLOOP>
Richard Meredith-Hardy 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!
>
> --
> Regards;
>
> Richard Meredith-Hardy
> -------------------------------------------------------------
> r[dot]mh[at]flymicro[dot]com
> Tel: + 44 (0)1462 834776 FAX: + 44 (0)1462 732668
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Sams Teach Yourself Regular Expressions in 10 Minutes by Ben Forta
http://www.houseoffusion.com/banners/view.cfm?bannerid=40
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:182235
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