Verilen yazıları 1 ve 0 lara çevirmenin basit bir yöntemi. Tam olarak ne işinize yarar bilemiyorum ama merak edenler varsa meraklarını giderebilirler.
class strToBin{
private $byteSeparator,$byte;
private $code;
function __construct($string,$byteSeparator=" ",$byte=1 /* 1byte = 8bits */){
$this->byte=$byte;
$this->byteSeparator=$byteSeparator;
$this->code=$this->stringToBinary($string);
}
private function charToBinary($char){
$charcode=ord($char);
$bits="";
while ($charcode>0) {
$bit=$charcode%2;
$charcode=(int)(floor($charcode/2));
$bits=$bit.$bits;
}
while (strlen($bits)<($this->byte*8)) {
if(strlen($bits)%8 == 0){
$bits=$this->byteSeparator.$bits;
}
$bits="0".$bits;
}
return $bits;
}
private function stringToBinary($string){
$code="";
while (true) {
$char=substr($string,$index,1);
if($char == null || $char== false){
break;
}
$bits=$this->charToBinary($char);
if(strlen($bits)%8 == 0){
$bits=$this->byteSeparator.$bits;
}
$code.=$bits;
$index++;
}
return $code;
}
function __toString(){
return $this->code;
}
}
$binary=new strToBin("By Brend");
echo $binary;
?>

Şubat 27th, 2008 at 11:53
verileri veritabanına kaydederken binary olarak kaydedilebilir ama bunun bi de geri dönüşünü yapmak lazım
Şubat 27th, 2008 at 12:45
if($char == null || $char== false)
satırı aşağıdaki gibi olmalı
if($char == null || $char===false)
Şubat 29th, 2008 at 22:00
Tabi ki decbin (http://php.net/decbin) ve bindec (http://php.net/bindec) fonksiyonlarınada bir göz atmak isteyebilirsiniz.