New In our Forum
help with a question by shawn
EOC's in North Carolina by sheenbreeze
Math Video Game! Play Decimals in Space! Use your reflexes & mathematical knowledge to shoot the right rocks!

A+    A−    B  
Home Page
Algebra
Games
Geometry
Interactive
Trigonometry
Forum
Math Jobs




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
Welcome Guest
Please Log in or register
Who's online: 11 Guests, 0 Users :        Please welcome newlove08, our newest member.
AddThis Social Bookmark Button Page copy protected against web site content infringement by Copyscape