Math Game! Play Integers in Space!


A+    A−    B  
Home
Algebra
Math Games
Geometry
Private Tutors
Interactive
Trigonometry
Jobs
Teacher Resources
On Facebook



AddThis Social Bookmark Button

Binary & Hexadecimal Calculator

Calculate/convert between Binary, Hexadecimal and Decimal



1) Type in a number in either binary, hex or decimal form



2) Select binary, hex or decimal output then calculate the number.

(Note: this calculator does not yet check to make sure that you have properly entered the numbers. So you have to enter valid hex or binary numbers. It will not stop you from entering 1K as a hexadecimal number even though K is not valid hex.)
Number to convert
Decimal input
Hexadecimal input
Binary input
Output

Decimal output
Hexadecimal output
Binary output


PHP code for these calculations
//input binary, output hex
//uses PHP's dechex function
function binaryToHex($binIn){
    $last = strlen($binIn)-1;
  for($i=0; $i<=$last; $i++){ $x += $binIn[$last-$i] * pow(2,$i); }
  return dechex($x);
}
Aahh yes, PHP is great and after using the function up above, I learned aobut the handy base_convert( ) function which lets you convert any number between whatever bases you'd like.
This function takes three arguments as follows base_convert($numberYouWantToConvert,$baseOfThatNumber, $baseToConvertTo). For example, running base_convert($hexInPut, 16, 2) will convert the the hexadecimal $hexInPut from base 16 to binary. And conversely, base_convert($binIn, 2, 16) converts the binary $binIn to hexadecimal.

Top
AddThis Social Bookmark Button