PHP/Math/base convert

Материал из Web эксперт
Перейти к: навигация, поиск

Convert integer values to other bases such as binary or base 32 and base 36

 
<?php
echo base_convert("123", 10, 10) . "\n";
echo base_convert("42", 10, 2) . "\n";
echo base_convert("83", 10, 8) . "\n";
echo base_convert("291", 10, 16) . "\n";
echo base_convert("124356", 10, 32) . "\n";
echo base_convert("987654", 10, 36) . "\n";
echo base_convert("abcd", 16, 8) . "\n";
echo base_convert("abcd", 16, 2) . "\n";
?>



function base_convert() converts any integer value from one base to another

 
<?php 
echo base_convert("123", 10, 10) . "\n"; 
echo base_convert("42", 10, 2) . "\n"; 
echo base_convert("83", 10, 8) . "\n"; 
echo base_convert("291", 10, 16) . "\n"; 

echo base_convert("558147", 10, 32) . "\n"; 
echo base_convert("794523", 10, 36) . "\n"; 

echo base_convert("abcd", 16, 8) . "\n"; 
echo base_convert("abcd", 16, 2) . "\n";
?>



string base_convert ( string num, int from_base, int to_base ) convert every base to every other base

 
<?
    print decbin(16);
    print base_convert("16", 10, 2);
?>