Preserved Topic: Bit vector -> array algorithm (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 05-14-2001 20:24
So I wrote this function: code: function vectorToArray($vector) {
|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
posted 05-14-2001 22:16 |
Paranoid (IV) Inmate From: other places |
posted 05-14-2001 22:26
The beauteous thing about your vectors is using the bitwise operations. You set bits with OR, you read them with AND. |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 05-14-2001 23:29
Ah I see. Very cool. I think my function still may have some use however. I've modified it so it returns an array of ints. code: function vectorToArray($vector) {
|
Paranoid (IV) Inmate From: other places |
posted 05-15-2001 01:37
you closed with a backslash, not slash. |
Maniac (V) Mad Scientist From: Rochester, New York, USA |
posted 05-15-2001 02:30
In essence you are preforming Decimal to Binary Conversions. code: public static String convert(int n)
code: /*
|
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 05-15-2001 22:59
Thanks warmage, PHP makes things much simpler because you never declare anything, just start filling the array. Yes, PHP does have bitshift, and I should have thought of using that. Your code appears to do more efficiently exactly what my original code did. I realized that a boolean array does not provide added value. |