Code Snippets

  

PHP Source Code


Welcome to Dream.In.Code
Become a PHP Expert!

Join 148,628 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,329 people online right now. Registration is fast and FREE... Join Now!





Convert a 64 bit number

This is a function to convert a 64 bit number since base_convert will choke on a number that size

Submitted By: PsychoCoder
Actions:
Rating:
Views: 7,537

Language: PHP

Last Modified: March 9, 2008
Instructions: Pass the function you wish to convert

Snippet


  1. //function to convert a 64 bit number
  2. function convert_64Bit ($str)
  3. {
  4.      $str = (string) $str;
  5.      while (!preg_match('/^0*$/', $str) && $j < 65)
  6.      {
  7.          $start_value = '';
  8.          $remainder = '';
  9.          //loop through the length of the number
  10.          for ($count = 0; $count < strlen($str); $count++)
  11.          {
  12.              //check the value of our start_value, if it's
  13.              //empty we need to keep looping
  14.              if ($start_value == '')
  15.              {
  16.                  //check the value of our values divided by 2
  17.                  if (floor(($str[$count] + $remainder) / 2))
  18.                  {
  19.                       $start_value .= floor(($str[$count] + $remainder) / 2);
  20.                  }
  21.              }
  22.              else
  23.              {
  24.                  $start_value .= floor(($str[$count] + $remainder) / 2);
  25.              }
  26.              $remainder = $str [$count] % 2 * 10;
  27.          }
  28.          //assign our temp variable ($x) with the value of
  29.          //$remainder value divided by 10
  30.          $x = floor($remainder / 10);
  31.          $final_value .= $num;
  32.          $str = $start_value;
  33.          $j++;
  34.      } 
  35.  return $final_value;
  36. }
  37.  

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month