1. Home
  2. Computing & Technology
  3. PHP / MySQL

Base_convert () PHP Function

By , About.com Guide

What is a base?: The base we are the most familiar with (our regular numeric system) is base 10. What this means is that, each 'slot' has 10 possibilities before a second digit is needed. For example we can have the digits 0-9 before needing to add a second digit. In binary, there are only two possibilities (0 or 1) before adding another digit. So, zero is 0 and one is 1, but two is written as 10, and three as 11.
Converting base: In PHP we can convert base simply using the base_convert () function. We need to specify the number, its current base, and the base we want to convert to. For example, converting 100 from base 10 to base 2 would be: base_convert (100, 10, 2)
Examples:
<?php
//Converting from base 2 and base 16 to base 10

$bi= '101101';
echo base_convert($bi, 2, 10) ;

$hex= 'A37443';
echo base_convert($hex, 16, 10) ;
?>
Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Base Convert - Base 10 to Binary PHP - PHP Base Change

©2009 About.com, a part of The New York Times Company.

All rights reserved.