|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
The humble tilde (~). I came across it the other day in some PHP code
Code:
~E_ERROR propostional logic, is it the same thing in PHP ? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Tue, Apr 8, 2008 at 6:19 AM, Tony Collings <tony@tonycollings.com> wrote:
> The humble tilde (~). I came across it the other day in some PHP code > Code:
~E_ERROR That comes from C, not postpositional math. It's bitwise negation. That is, the number 47 in binary is 110001, with leading 0's out to whatever the word size is, usually 32 or 64 bits. The ~ flips the bits, so on a 32-bit system ~47 is binary 11111111111111111111111111001110, which is -48 if you treat it as a signed value and 429496248 as unsigned. The tilde is most often seen in the company of flag values, where each bit represents an option that is on or off. Typically, you have a bunch of constants defined as the individual bit values, like say E_DEBUG. Then ~E_DEBUG means "turn on everything except E_DEBUG". Often used with bitwise AND (&) as a mask to turn a particular bit off, as in <?php $flags &= ~E_DEBUG ?> which turns off E_DEBUG while leaving the other bits in $flag unchanged. -- Mark J. Reed <markjreed@mail.com> |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Ah! excellent. Thanks for that.
------------------------------------------------------------- e. tony@tonycollings.com w. www.tonycollings.com skype. supert3d United States of America t. 1-203-599-1604 m. 1-203-788-7787 United Kingdom t. 020 8144 2453 m. 07763803980 -----Original Message----- From: markjreed@gmail.com [mailto:markjreed@gmail.com] On Behalf Of "Mark J. Reed" Posted At: 08 April 2008 08:50 Posted To: php.general Conversation: Could someone tell me what a tilde(~) in PHP does ? Subject: Re: [php] Could someone tell me what a tilde(~) in PHP does ? On Tue, Apr 8, 2008 at 6:19 AM, Tony Collings <tony@tonycollings.com> wrote: > The humble tilde (~). I came across it the other day in some PHP code > Code:
~E_ERROR That comes from C, not postpositional math. It's bitwise negation. That is, the number 47 in binary is 110001, with leading 0's out to whatever the word size is, usually 32 or 64 bits. The ~ flips the bits, so on a 32-bit system ~47 is binary 11111111111111111111111111001110, which is -48 if you treat it as a signed value and 429496248 as unsigned. The tilde is most often seen in the company of flag values, where each bit represents an option that is on or off. Typically, you have a bunch of constants defined as the individual bit values, like say E_DEBUG. Then ~E_DEBUG means "turn on everything except E_DEBUG". Often used with bitwise AND (&) as a mask to turn a particular bit off, as in <?php $flags &= ~E_DEBUG ?> which turns off E_DEBUG while leaving the other bits in $flag unchanged. -- Mark J. Reed <markjreed@mail.com> |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Tue, Apr 8, 2008 at 8:50 AM, Mark J. Reed <markjreed@mail.com> wrote:
> That is, the number 47 in binary is 110001, " .... or 101111, if you want to be technical. 110001 is 49. ![]() "The important thing is to understand what you're doing, rather than to get the right answer." --Tom Lehrer -- Mark J. Reed <markjreed@mail.com> |
|
![]() |
| Outils de la discussion | |
|
|