2進位換算

<?php
/*
2進位換算
*/
class abc{
    const MAGIC = 0xA4424225;
    const BUYER = 0xAA;
    public $id =45;
    public function convS2H($id) {
        $id = self::MAGIC ^ ($id * self::BUYER);
        return strtoupper(dechex($id));
    }
    public function convH2S($hid) {
        $hid = hexdec($hid);
        return (self::MAGIC ^ $hid) / self::BUYER;
    }
}
$id=45;
$abc2= new abc;
$a01=$abc2->convS2H($id);
$a02=$abc2->convH2S($a01);
print_r($a01);
echo “<br>\n”;
print_r($a02);
echo “<br>”;
$id=45;
$MAGIC=0xA4424225;
$BUYER=0xAA;
        $id = $MAGIC ^ ($id * $BUYER);
        $a01= strtoupper(dechex($id));
        $hid = hexdec($a01);
        $a02= ($MAGIC ^ $hid) /$BUYER;
print_r($a01);
echo “<br>\n”;
print_r($a02);

#答案


A4425FC7
45
A4425FC7
45

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *