Professional Web Applications Themes

Binary calculations (OR, AND, XOR) - PHP Development

Hey, Anybody knows a possible way to do binary calculations (OR, AND, XOR). Anything I type before 'AND' will be outputted, but the AND-word and anything behind it is ignored. E.g. [/ref] results in 3. My PHP-version is 4.2.3. Thanx!...

  1. #1

    Default Binary calculations (OR, AND, XOR)

    Hey,
    Anybody knows a possible way to do binary calculations (OR, AND, XOR).
    Anything I type before 'AND' will be outputted, but the AND-word and
    anything behind it is ignored. E.g. [/ref]
    results in 3.

    My PHP-version is 4.2.3.

    Thanx!
    Siebie Guest

  2. #2

    Default Re: Binary calculations (OR, AND, XOR)

    "Siebie" <com> kirjoitti
    viestissä:109.133.133... [/ref]
    > results in 3.
    >
    > My PHP-version is 4.2.3.[/ref]


    Binary calculations are done with the binary (or bitwise) operators & | ^
    and ~, >> and <<.

    Examples:

    echo (1 & 2); // Prints 0, since 0001 AND 0010 equals 0000
    echo (1 | 2); // Prints 3, since 0001 OR 0010 equals 0011
    echo ~(6 ^ 9) // prints 16, since NOT(0110 XOR 1001) equals !0000 equals
    1111...

    Etc... I just pulled the binary numbers from my hat, and my boolean math is
    rusty, so errors may occur, but you get the point... And I assume this was
    what you were looking for. See the manual on bitwise operators for more.

    --
    SETI Home - Donate your cpu's idle time to science.
    Further reading at <http://setiweb.ssl.berkeley.edu/>
    Kimmo Laine <com>


    Kimmo Guest

  3. #3

    Default Re: Binary calculations (OR, AND, XOR)

    "Kimmo Laine" <com> wrote in
    news:de7ijr$8vq$kolumbus.fi:
     

    This is exact what I was looking for!
    Thanx!
    Siebie Guest

Similar Threads

  1. Calculations in a form
    By Kathy_Neal@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: December 8th, 02:10 PM
  2. Calculations in datagrid
    By kchalla in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: May 16th, 08:56 PM
  3. Replies: 5
    Last Post: June 26th, 12:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139