Fungsi PHP base_convert()
Contoh
Konversi bilangan heksadesimal ke bilangan oktal:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
Definisi dan Penggunaan
Fungsi base_convert() mengonversi angka dari satu basis angka ke basis angka lainnya.
Sintaksis
base_convert(number,frombase,tobase);
Nilai Parameter
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 |
Detail Teknis
Nilai Kembali: | Nomor yang dikonversi ke basis yang ditentukan |
---|---|
Jenis pengembalian: | Rangkaian |
Versi PHP: | 4+ |
Lebih Banyak Contoh
Contoh
Mengubah bilangan oktal menjadi bilangan desimal:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
Contoh
Mengubah bilangan oktal menjadi bilangan heksadesimal:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
Referensi Matematika PHP