<?php

// ByteBit type (c) yoya@awm.jp

class ByteBit {
    var 
$byte 0;
    var 
$bit  0;
    function 
ByteBit($byte$bit) {
        
$this->byte $byte;
        
$this->bit $bit;
    }
    function 
add($x) {
        
$byte $this->byte $x->byte;
        
$bit  $this->bit  $x->bit;
        if (
$bit 7) {
            
$byte += (int) ($bit 8);
            
$bit %= 8;
        }
        return new 
ByteBit($byte$bit);
    }
    function 
diff($x) {
        
$byte $this->byte $x->byte;
        
$bit  $this->bit  $x->bit;
        while (
$bit 0) {
            
$byte -= 1;
            
$bit += 8;
        }
        return new 
ByteBit($byte$bit);
    }
    function 
cmp($x) {
        if (
$this->byte $x->byte) {
            return 
1// greater than
        
}
        if (
$this->byte == $x->byte) {
            if (
$this->bit $x->bit) {
                return 
1// greater than
            
}
            if (
$this->bit == $x->bit) {
                return 
0// equal
            
}
        }
        return -
1// less than
    
}
}