PHP ပရိုဂရမ်တွင်ကိန်းဂဏန်းတန်ဖိုးများကိုကွဲပြားသောဂဏန်းများအကြားကွဲပြားခြားနားသောဂဏန်းများအကြားပြောင်းလဲရန်လိုအပ်လေ့ရှိသည်။ Hexadecimal နံပါတ်များကိုဒ decimal မဟုတ်သည့်နံပါတ်များကိုပြောင်းလဲရန်နှင့်ဒ decimalum နံပါတ်များကို decimals နံပါတ်များကိုပြောင်းလဲရန်အသုံးပြုသော PHP တွင်အလွန်အဆင်ပြေသော built-in functions hexdec () dechex () ကို ထောက်ပံ့ပေးသည်။
HexDec () function သည် hex string ကိုအငြင်းပွားမှုအဖြစ်ယူပြီးသက်ဆိုင်ရာဒ decimal မကိန်းကိုပြန်ပို့သည်။ အသုံးပြုသည့်အခါ hexadecimal နံပါတ်များပါသည့် string တစ်ခုတွင်သာဖြတ်ပါ။
<?php
$hex = "1A3F";
$decimal = hexdec($hex);
echo "hexadecimal နံပါတ် {$hex} ဒ decimal မမှပြောင်းလဲ: {$decimal}";
?>
ထုတ်လုပ်မှု -
hexadecimal နံပါတ် 1A3F ဒ decimal မမှပြောင်းလဲ: 6719
Dechele () function သည် decimal ကိန်းတစ်ခုအနေဖြင့်အငြင်းပွားမှုအဖြစ်ယူပြီးသက်ဆိုင်ရာ hexadecimal string ကိုပြန်ပို့သည်။
<?php
$decimal = 6719;
$hex = dechex($decimal);
echo "ဒ decimal မကိန်း {$decimal} hexadecimal သို့ပြောင်းရန်: {$hex}";
?>
ထုတ်လုပ်မှု -
ဒ decimal မကိန်း 6719 hexadecimal သို့ပြောင်းရန်: 1a3f
Rewarded hexadecimal string သည်ပုံမှန်အားဖြင့်စာလုံးအသေးဖြစ်သည်ကိုသတိပြုပါ။ စာလုံးအကြီးလိုအပ်ပါက strutupper () function ကိုပေါင်းစပ်နိုင်သည်။
<?php
$hex = strtoupper(dechex($decimal));
echo "မြို့တော် hexadecimal: {$hex}";
?>
ထုတ်လုပ်မှု -
မြို့တော် hexadecimal: 1A3F
အသုံးပြုသူသည် hexadecimal နံပါတ်တစ်ခုထဲသို့ 0 င်ရောက်ပြီးသက်ဆိုင်ရာဒ decimal မကိန်းကို အသုံးပြု. သက်ဆိုင်ရာဒ decimal မကိန်းကိုပြသထားသည့်ဆိုပါစို့။
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['hex'])) {
$hex = $_POST['hex'];
$decimal = hexdec($hex);
echo "<p>hexadecimal {$hex} ဒ decimal မမှပြောင်းလဲ {$decimal}</p>";
}
if (!empty($_POST['decimal'])) {
$decimal = (int)$_POST['decimal'];
$hex = dechex($decimal);
echo "<p>ဒက်မချက် {$decimal} hexadecimal သို့ပြောင်းရန် {$hex}</p>";
}
}
?>
<form method="post" action="https://gitbox.net/convert.php">
<label>hexadecimal: <input type="text" name="hex"></label><br>
<label>ဒက်မချက်: <input type="text" name="decimal"></label><br>
<input type="submit" value="ပေြာင်း">
</form>
ဤဥပမာတွင်အသုံးပြုသူသည်မည်သည့် hexadecimal သို့မဟုတ် decimal နံပါတ်ကိုပုံစံဖြင့်မဆိုအသုံးပြုနိုင်ပြီးတင်သွင်းပြီးသည့်နောက်တွင်နောက်ခံသည်သက်ဆိုင်ရာပြောင်းလဲခြင်းနှင့်ရလဒ်များကိုပြသလိမ့်မည်။