Not a fibonacci series

Greg Rundlett greg at freephile.com
Thu Feb 26 00:18:41 EST 2004


Thanks for pointing out this is easily done in binary.  My goal was to 
come up with a way for ordinary editors to codify a business partner 
with a value that was easily parsed by the program logic to determine 
the status of a business partner.

Using a binary representation, the editor can just use 1's and 0's to 
indicate whether the partner is a member of class a, b, c, or d.  It is 
a lot easier to enter a value of '0110' compared with having to remember 
or lookup that '6' decimal is the code for the 'b,c' combination.

In the backend processing, I can convert the binary string to decimal 
for further processing by business rules.  To paraphrase: "if partner 
value is 6, they are members of the b and c clubs.

Here is some simple PHP code that illustrates the *base_convert()* function:

<?php

$binaryValues = array(
'0000',
'0001',
'0010',
'0011',
'0100',
'0101',
'0110',
'0111',
'1000',
'1001',
'1010',
'1011',
'1100',
'1101',
'1110',
'1111'
);
foreach ($binaryValues as $k=>$v) {
   print  $k+1 . ". converting <b>$v</b> to base 10 = <b>" . 
base_convert($v, 2, 10) . "</b><br />\n";
}

?>

results in this output:

1. converting 0000 to base 10 = 0
2. converting 0001 to base 10 = 1
3. converting 0010 to base 10 = 2
4. converting 0011 to base 10 = 3
5. converting 0100 to base 10 = 4
6. converting 0101 to base 10 = 5
7. converting 0110 to base 10 = 6
8. converting 0111 to base 10 = 7
9. converting 1000 to base 10 = 8
10. converting 1001 to base 10 = 9
11. converting 1010 to base 10 = 10
12. converting 1011 to base 10 = 11
13. converting 1100 to base 10 = 12
14. converting 1101 to base 10 = 13
15. converting 1110 to base 10 = 14
16. converting 1111 to base 10 = 15








More information about the gnhlug-discuss mailing list