Kay,
I'll assume he hands you a number like 8 and you have to determine that it
contains categories 1,2 and 4.
IMHO, your DB engineer should be doing the decomposition in SQL and you
should make them provide a proc to do this.
What you're trying to do *IS* possible in CF. You can't perform certain
mathmatical operations on a double primitive in CF. However, you *can*
decompose it using a loop. You just can't get your starting position unless
it is < 32 bits.
Of course, if you're dealing with 31 bits, the best approach is to grab your
starting position of the decomposition and go from there.
If not, then you just get rid of the outer loop and set i=64 or i=128 or
whatever.
You can do this in Java but it is inaccurate do to datatype demotion during
the shift.
==========
Example A:
// initialize array
aBitMask = arrayNew(1);
// initilize vars
str2bin = '';
// set tmp var for decimal to binary algorithm
tmp = bitMaskInteger;
while(tmp GT 0) {
if(tmp MOD 2 GT 0) {
str2bin = 1 & str2bin;
} else {
str2bin = 0 & str2bin;
}
tmp = int(tmp / 2);
}
// count bits
bitsize = len(str2bin);
// set counter to bit size
i = bitsize;
// calculate bit number
bitNumber=2^(bitsize - 1);
// decompose bitmask
while(i GT 0 and arguments.bitMaskInteger GT 0) {
if(arguments.bitMaskInteger GTE bitNumber) {
arrayAppend(aBitMask,numberFormat(bitNumber,'0'));
arguments.bitMaskInteger=arguments.bitMaskInteger-bitNumber;
}
/* remove comment to see algorithm in motion
WriteOutput("bitMaskInteger:" & arguments.bitMaskInteger & "<br />"
& "bitMaskIntger in binary:" & str2bin & "<br />"
& "bitNumber:" & bitNumber & "<br />"
& "Counter:" & i & "<br />"
& "Bitsize:" & bitsize & "<br />"
& "<hr />");
*/
// decrement bitNumber
bitNumber = bitNumber / 2;
// decrement counter
i = i - 1;
}
==================
Example B:
If over 31 bits, hardcode i=64 or 128 and you just have further to go until
you get to your decomposed data.
i=64;
bitNumber=2^(i-1);
while(i GT 0 and arguments.bitMaskInteger GT 0){
if(arguments.bitMaskInteger GTE bitNumber){
arrayAppend(aBitMask,numberFormat(bitNumber,'0'));
arguments.bitMaskInteger=arguments.bitMaskInteger-bitNumber;
}
bitNumber = bitNumber / 2;
i = i - 1;
}
-------------->
Warmest Regards,
Phillip B. Holmes
http://phillipholmes.com
--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.4/424 - Release Date: 8/21/2006
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:251457
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4