PHP base remainder-php Tutorial

Source: Internet
Author: User
PHP base remainder
I want to know what is 21712341byte in K bit, M bit, G bit? This is equivalent to the problem of hexadecimal conversion. However, the hexadecimal value to be converted is 1024.




  1. // Obtain the value in the base space.
  2. Function getRemainder ($ num, $ bin, $ pos, & $ result = 0 ){
  3. // Author lianq.net
  4. // $ Num value, decimal
  5. // $ Bin: the hexadecimal format to be converted
  6. // $ Pos digits
  7. $ Real_len = log ($ num, $ bin); // logarithm, evaluate the original value length
  8. $ Floor_len = floor ($ real_len); // trim
  9. $ Base = pow ($ bin, $ pos-1); // base
  10. $ Pisor = pow ($ bin, $ pos); // divisor
  11. If ($ num >=$ pisor ){
  12. $ New_num = $ num % pow ($ bin, $ floor_len );
  13. GetRemainder ($ new_num, $ bin, $ pos, $ result );
  14. } Else {
  15. $ Result = floor ($ num/$ base );
  16. }
  17. Return $ result;
  18. }
  19. // For example, when a value 16 is converted to a 9-digit value, what is the value at the first place?
  20. $ A = getRemainder (16, 9, 1 );
  21. Echo $ a; // output 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.