PHP takes remainder

WBOY
Release: 2016-07-25 09:08:21
Original
959 people have browsed it
I want to know what 21712341byte is in the K position, what about the M position, and the G position? This is equivalent to a hexadecimal conversion problem. It’s just that the base system to be converted now is 1024.                  
                                                                                                                                                                                                                                                                                                       



//Get the numerical value in the base digit
function getRemainder($num, $bin, $pos, &$result = 0){
//author         lianq.net
    //$num                                                                                                                                                     but the numeric value in decimal digits
  1. function getRemainder($num, $bin, $pos, &$result = 0){ /$bin The base to be converted
  2. //$pos The number of digits
  3. To find the integer
  4.                                                                                                                                          $new_num = $num % pow($bin, $floor_len);
  5. $remainder($new_num, $bin, $pos, $result);
  6. }else{
  7. $result = floor($num / $base);
  8. }
  9. return $result;
  10. }
  11. //For example, when the value 16 is converted to base 9, what is the first digit of it?
  12. $a = getRemainder(16,9, 1);
  13. echo $a;//Output 7
  14. Copy code
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template