phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP Operators: Bitwise Operators

Tag: operator, Bitwise Operators   Category: PHP Basic
post: 08 Mar 2008 read: 646


PHP Operators Step By Step Tutorial - Part 5: Bitwise operator is operator that is used for the bit operation (binary digit) in level (0 and 1).
Operator Info Example
In Decimal In Binner
& AND 9
8 &
8
1001
1000 &
1000
| OR 9
8 |
9
1001
1000 |
1000
^ XOR 9
8 ^
9
1001
1000 ^
1000
~ NOR ~9 (decimal) = -
11 (decimal)
<< shift leftly 9<<1
= 1
>> shift right 9>>1
= 4

In fact, bit operator inspiration of its ability at C Ianguage, but at php script is seldom to be used. Pay attention to the example of using bit operator at script as following:

File name: bitoperator.php


<html>
<head>
<title>Using Bit Operator</title>
</head>

<body>
<h1>The example for using bitwise operator</h1>
<?
printf("7 & 15 = %d <br>", 7 & 15);
printf("7 | 15 = %d <br>", 7 | 15);
printf("7 ^ 15 = %d <br>", 7 ^ 15);
printf("~7= %d <br>", ~7);
printf("7 << 1 = %d <br>", 7 << 1);
printf("7 >> 1 = %d <br>", 7 >> 1);
?>
</body>
</html>

The result of executing bitwise operator.php:

bit operator


Series this article:
PHP Operators: Introduction
PHP Operators: Arithmetic Operators
PHP Operators: Assignment Operators
PHP Operators: Assignment Operators Table
PHP Operators: Bitwise Operators
PHP Operators: Relation Operators
PHP Operators: Ternary Operator
PHP Operators: Error Control Operator
PHP Operators: Execution Operator
PHP Operators: Increment or Decrement Operator
php Operators: Logic Operator
PHP Operators: String Operator
PHP Operators: Array Operator
PHP Operators: Object Operator
PHP Operators: Operator Priority
PHP Constants: Introduction

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting