PHP bin2hex() 函數
PHP bin2hex() 函數用于將 ASCII 字符串轉換為十六進制值。愛掏網 - it200.com
string bin2hex ( string $str )
參數 | 描述 | 必需/可選 |
---|---|---|
字符串 | 要轉換的字符串 | 必需 |
示例1
<?php
str ="Hello World!";
echo "Your ASCII character is: ".str;
echo "<br>"."By using 'bin2hex()' Method your hexadecimal value is: ".bin2hex($str);
?>
輸出:
Your ASCII character is:Hello World!
By using 'bin2hex()' Method your hexadecimal value is: 48656c6c6f20576f726c6421
注意:將一個字符串值轉換為二進制數再轉為十六進制。愛掏網 - it200.com
示例2
<?php
str = "Hello world!";
echo "Your Hexadecimal Value is ".bin2hex(str) . "<br>";
echo pack("H*",bin2hex($str)) . "<br>";
?>
輸出:
Your Hexadecimal Value is 48656c6c6f20776f726c6421
Hello world!
示例3
<?php
binary = "11111001";
echo "Your Binary Value is".binary."<br>";
hex = dechex(bindec(binary));
echo "Converted Binary to Hexadecimal : ".$hex;
?>
輸出:
Your Binary Value is11111001
Converted Binary to Hexadecimal : f9
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。