دالة PHP base_convert ()
مثال
تحويل رقم سداسي عشري إلى رقم ثماني:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
التعريف والاستخدام
تقوم الدالة base_convert () بتحويل رقم من رقم أساسي إلى آخر.
بناء الجملة
base_convert(number,frombase,tobase);
قيمه المعامل
Parameter | Description |
---|---|
number | Required. Specifies the number to convert |
frombase | Required. Specifies the original base of number. Has to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35 |
tobase | Required. Specifies the base to convert to. Has to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35 |
تفاصيل تقنية
قيمة الإرجاع: | الرقم المحول إلى الأساس المحدد |
---|---|
نوع الإرجاع: | سلسلة |
إصدار PHP: | 4+ |
مزيد من الأمثلة
مثال
تحويل رقم ثماني إلى رقم عشري:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
مثال
تحويل رقم ثماني إلى رقم سداسي عشري:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
❮ مرجع الرياضيات PHP