Skip to content

Instantly share code, notes, and snippets.

@linkmckinney
Created July 17, 2012 14:24
Show Gist options
  • Save linkmckinney/3129695 to your computer and use it in GitHub Desktop.
Save linkmckinney/3129695 to your computer and use it in GitHub Desktop.
BitAnd exercise
<cfcomponent output="false">
<cffunction name="valueSearch" returntype="Any" access="remote">
<cfargument name="searchVar" type="numeric" required="true"/>
<cfset var local.msg = ''>
<cftry>
<cfset local.bitAR = arrayNew(1) />
<cfset local.bitAR[1] = { bit = 512, name = 'Other' } />
<cfset local.bitAR[2] = { bit = 256, name = 'Authority' } />
<cfset local.bitAR[3] = { bit = 128, name = 'Claims' } />
<cfset local.bitAR[4] = { bit = 64, name = 'Service Failure' } />
<cfset local.bitAR[5] = { bit = 32, name = 'Safety Rating' } />
<cfset local.bitAR[6] = { bit = 16, name = 'Pending Authority' } />
<cfset local.bitAR[7] = { bit = 8, name = 'Profile' } />
<cfset local.bitAR[8] = { bit = 4, name = 'Agreement' } />
<cfset local.bitAR[9] = { bit = 2, name = 'W9' } />
<cfset local.bitAR[10] = { bit = 1, name = 'Insurance' } />
<cfloop from="1" to="#arrayLen(local.bitAR)#" index="local.i">
<cfloop from="1" to="#arguments.searchVar#" index="local.x">
<cfif BitAnd(arguments.searchVar-local.x, local.bitAR[local.i].bit)>
<cfset local.msg = listAppend(local.msg, local.bitAR[local.i].name)>
<cfbreak>
</cfif>
</cfloop>
</cfloop>
<cfcatch type="any" >
<cfset local.msg = cfcatch.Message>
</cfcatch>
</cftry>
<cfreturn local.msg>
</cffunction>
</cfcomponent>
<cfinvoke component="bitSearch" method="valueSearch" returnvariable="result">
<cfinvokeargument name="searchVar" value="10">
</cfinvoke>
<cfdump var="#result#"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment