PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Could someone tell me what a tilde(~) in PHP does ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Could someone tell me what a tilde(~) in PHP does ?

Réponse
 
LinkBack Outils de la discussion
Vieux 08/04/2008, 11h19   #1
Tony Collings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Could someone tell me what a tilde(~) in PHP does ?

The humble tilde (~). I came across it the other day in some PHP code
Code:
~E_ERROR
I'm curious, can't find any documentation on it. In math it refers to
propostional logic, is it the same thing in PHP ?


  Réponse avec citation
Vieux 08/04/2008, 13h50   #2
Mark J. Reed
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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>
  Réponse avec citation
Vieux 08/04/2008, 14h18   #3
Tony Collings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Could someone tell me what a tilde(~) in PHP does ?

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>

  Réponse avec citation
Vieux 08/04/2008, 14h29   #4
Mark J. Reed
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Could someone tell me what a tilde(~) in PHP does ?

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>
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h34.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10822 seconds with 12 queries