Re: [PHP] Help with some clever bit operations

2006-06-13 Thread David Tulloh
The example starting values $existing = 181; # = 10110101 $new = 92; # = 01011100 $mask = 15; # = Get the bits that will be changed $changing = $new $mask; # = 12 = 1100 Get the bits that won't be changed $staying = $existing ~$mask; # = 176 = 1011 Combine them together

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Jochem Maas
Niels wrote: Hi, I have a problem I can solve with some loops and if-thens, but I'm sure it can be done with bit operations -- that would be prettier. I've tried to work it out on paper, but I keep missing the final solution. Maybe I'm missing something obvious... The problem: A function

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Jochem Maas
David Tulloh wrote: The example starting values $existing = 181; # = 10110101 $new = 92; # = 01011100 $mask = 15; # = Get the bits that will be changed $changing = $new $mask; # = 12 = 1100 Get the bits that won't be changed $staying = $existing ~$mask; # = 176 =

RE: [PHP] Help with some clever bit operations

2006-06-13 Thread Ford, Mike
On 13 June 2006 10:31, Niels wrote: Hi, I have a problem I can solve with some loops and if-thens, but I'm sure it can be done with bit operations -- that would be prettier. I've tried to work it out on paper, but I keep missing the final solution. Maybe I'm missing something obvious...

RE: [PHP] Help with some clever bit operations

2006-06-13 Thread Niels
On Tuesday 13 June 2006 12:32, Ford, Mike wrote: On 13 June 2006 10:31, Niels wrote: Hi, I have a problem I can solve with some loops and if-thens, but I'm sure it can be done with bit operations -- that would be prettier. I've tried to work it out on paper, but I keep missing the

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Niels
On Tuesday 13 June 2006 12:22, Jochem Maas wrote: Niels wrote: Hi, I have a problem I can solve with some loops and if-thens, but I'm sure it can be done with bit operations -- that would be prettier. I've tried to work it out on paper, but I keep missing the final solution. Maybe I'm

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Niels
On Tuesday 13 June 2006 12:18, David Tulloh wrote: The example starting values $existing = 181; # = 10110101 $new = 92; # = 01011100 $mask = 15; # = Get the bits that will be changed $changing = $new $mask; # = 12 = 1100 Get the bits that won't be changed $staying =

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Satyam
- Original Message - From: David Tulloh [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Tuesday, June 13, 2006 12:18 PM Subject: Re: [PHP] Help with some clever bit operations The example starting values $existing = 181; # = 10110101 $new = 92

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Robert Cummings
On Tue, 2006-06-13 at 06:22, Jochem Maas wrote: My brain needs a crutch when trying doing this kind of thing (normally I only write hex number literally when dealing with bitwise stuff - the conversion stuff still makes my head spin) - this is what this table is for: 128 64 32 16 8 4 2 1

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Jochem Maas
Robert Cummings wrote: On Tue, 2006-06-13 at 06:22, Jochem Maas wrote: My brain needs a crutch when trying doing this kind of thing (normally I only write hex number literally when dealing with bitwise stuff - the conversion stuff still makes my head spin) - this is what this table is for:

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Robert Cummings
On Tue, 2006-06-13 at 11:03, Jochem Maas wrote: Robert Cummings wrote: On Tue, 2006-06-13 at 06:22, Jochem Maas wrote: My brain needs a crutch when trying doing this kind of thing (normally I only write hex number literally when dealing with bitwise stuff - the conversion stuff still

Re: [PHP] Help with some clever bit operations

2006-06-13 Thread Jochem Maas
Robert Cummings wrote: On Tue, 2006-06-13 at 11:03, Jochem Maas wrote: Robert Cummings wrote: On Tue, 2006-06-13 at 06:22, Jochem Maas wrote: My brain needs a crutch when trying doing this kind of thing (normally I only write hex number literally when dealing with bitwise stuff - the