PHP Classes
elePHPant
Icontem

File: bitops.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of mehmet emin akyüz  >  BMP2GD  >  bitops.php  >  Download  
File: bitops.php
Role: Auxiliary script
Content type: text/plain
Description: Simple utility functions to handle bit operations
Class: BMP2GD
Convert images in the BMP format
Author: By
Last change:
Date: 5 years ago
Size: 671 bytes
 

Contents

Class file image Download
<?php
function getBit($bytes,$n)
{
   
$n=1<<$n;
    return
$bytes & $n;
}

function
setBit($bytes,$n)
{
   
$n=1<<$n;
    return
$bytes | $n;
}

function
printBits($bytes,$l=8,$d=0)
{
   
$b='';
    for(
$i=$l-1;$i>-1;--$i){
        if(
$i!=0 && $d!=0 && $i%$d==0)$b.=' ';
        if(
getBit($bytes,$i))$b.='1';
        else
$b.='0';
    }
    return
$b;
}

function
printBitsR($bytes,$l=8,$d=0)
{
   
$b='';
    for(
$i=0;$i<$l;++$i){
        if(
$i!=0 && $d!=0 && $i%$d==0)$b.=' ';
        if(
getBit($bytes,$i))$b.='1';
        else
$b.='0';
    }
    return
$b;
}

function
getBitsetInt($bytes,$bitCount,$n){
   
$x=0;
   
$y=$bytes;
    for(
$i=0;$i<$bitCount;++$i){
       
$x|= (1 << $i);
    }
   
    for(
$i=0;$i<$n;$i++){
       
$y=$y >> 1;
    }
   
    return
$x & $y;
}
?>