PHP remainder function code _ PHP

Source: Internet
Author: User
I want to know what is 21712341byte in K bit, M bit, G bit? This is equivalent to the problem of hexadecimal conversion. But the hexadecimal value to be converted is 1024. The code is as follows:
// Obtain the value in the base space.
Function getRemainder ($ num, $ bin, $ pos, & $ result = 0 ){
// Author lianq.net
// $ Num value, decimal
// $ Bin: the hexadecimal format to be converted
// $ Pos digits
$ Real_len = log ($ num, $ bin); // logarithm, evaluate the original value length
$ Floor_len = floor ($ real_len); // trim
$ Base = pow ($ bin, $ pos-1); // base
$ Pisor = pow ($ bin, $ pos); // divisor
If ($ num >=$ pisor ){
$ New_num = $ num % pow ($ bin, $ floor_len );
GetRemainder ($ new_num, $ bin, $ pos, $ result );
} Else {
$ Result = floor ($ num/$ base );
}
Return $ result;
}

// For example, when a value 16 is converted to a 9-digit value, what is the value at the first place?
$ A = getRemainder (16, 9, 1 );
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.