Author Topic: PHP bitstrings.lib.php  (Read 1717 times)

Offline chaos

  • BFF
  • ***
  • Posts: 291
  • Job, school, social life, sleep. Pick 2.5.
    • View Profile
    • Lost Souls
PHP bitstrings.lib.php
« on: September 14, 2008, 08:11:06 PM »
These utility functions implement equivalents of the basic LPC bitstring-manipulation functions in PHP.

Code: [Select]
<?php

function bitstring_test($bs$ix) {
    
$which floor($ix 6);
    
$bits ord($bs[$which]) - 32;
    
$test << ($ix 6);
    return (
$bits $test) && true;
}

function 
bitstring_set($bs$ix) {
    
$which floor($ix 6);
    if(
$which strlen($bs)) {
        
$bits ord($bs[$which]) - 32;
    } else {
        
$bs .= str_repeat(' '$which strlen($bs) + 1);
        
$bits 0;
    }
    
$bits |= << ($ix 6);
    return 
substr_replace($bschr($bits 32), $which1);
}

function 
bitstring_clear($bs$ix) {
    
$which floor($ix 6);
    if(
$which strlen($bs))
        
$bits ord($bs[$which]) - 32;
    else
        return 
$bs;
    
$bits &= ~(<< ($ix 6));
    return 
substr_replace($bschr($bits 32), $which1);
}

?>