PHP取进制余数函数代码_PHP
//取进制位上的数值
function getRemainder($num, $bin, $pos, &$result = 0){
//author lianq.net
//$num 数值,十进制
//$bin 要转换的进制
//$pos 位数
$real_len = log($num, $bin);//对数,求原值长度
$floor_len = floor($real_len);//舍去求整
$base = pow($bin, $pos-1);//基数
$divisor = pow($bin,$pos);//除数
if($num >= $divisor){
$new_num = $num % pow($bin, $floor_len);
getRemainder($new_num, $bin, $pos, $result);
}else{
$result = floor($num / $base);
}
return $result;
}
//比如,数值16转换为9进制时,它的第一位上的数值是多少?
$a = getRemainder(16,9, 1);
echo $a;//输出7

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Use the strconv.FormatInt function to convert an integer into a string in a specified base. In the Go language, the strconv package is a commonly used package for converting between strings and other data types. The strconv.FormatInt function can convert an integer into a string in a specified base. This article will introduce the use of strconv.FormatInt and provide some sample code. First, let's take a look at strconv.FormatIn

Title: Use PHP to convert strings to hexadecimal and achieve reverse output. In daily development, we sometimes need to convert strings to hexadecimal representation for data transmission or encryption. This article will introduce how to use PHP to convert a string into hexadecimal and realize the reverse output function. First, we need to write a PHP function to convert a string to hexadecimal. The following is an example code: functionstringToHex($string)

Methods to solve Chinese garbled characters when converting hexadecimal strings in PHP. In PHP programming, sometimes we encounter situations where we need to convert strings represented by hexadecimal into normal Chinese characters. However, in the process of this conversion, sometimes you will encounter the problem of Chinese garbled characters. This article will provide you with a method to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP, and give specific code examples. Use the hex2bin() function for hexadecimal conversion. PHP’s built-in hex2bin() function can convert 1

How to use the MOD function in MySQL to calculate the remainder of two numbers. In MySQL, the MOD function is a very convenient function that can be used to calculate the remainder of two numbers. In mathematics, a remainder is the part of a division that is not divisible. In computer programming, we often need to use remainders to complete various tasks, such as determining whether a number is odd or even, determining whether two numbers are divisible, etc. MySQL's MOD function can help us quickly and accurately calculate the remainder of two numbers. The following will introduce how to use it.

Title: Easily learn to convert hexadecimal to binary in Go language. Specific code examples are required. In computer programming, conversion operations between different base numbers are often involved. Among them, conversion between hexadecimal and binary is relatively common. In the Go language, we can achieve hexadecimal to binary conversion through some simple code examples. Let us learn together. First, let's take a look at the representation methods of hexadecimal and binary. Hexadecimal is a method of representing numbers, using 0-9 and A-F to represent 1

Title: PHP converts a string to hexadecimal and reversely outputs it. In network programming, sometimes it is necessary to convert a string to hexadecimal format and restore the original string when outputting in reverse. As a popular server-side scripting language, PHP provides rich string processing functions and hexadecimal conversion functions, which can easily complete this task. This article will introduce how to convert a string to hexadecimal and reverse output through PHP, and provide specific code examples. Step 1: Convert string to hexadecimal First, we need to write a P

How to perform accurate integer division and remainder calculations in Go language. When performing integer division and remainder calculations in Go language, we need to pay attention to the loss of precision in integer operations. To ensure accurate divisions and remainders, we can use some tricks and functions. Integer division operations can be implemented using the Floor function in the math package. This function can return the maximum integer value that is no greater than the given argument. Therefore, we can get the exact integer quotient by first dividing by the divisor and then rounding using the Floor function.

PHP octal: Decrypting the programmer's coding password Introduction: In the world of programmers, coding is one of the most basic skills. Coding enables computers to understand and execute our instructions to complete various tasks. However, sometimes programmers may need to encrypt data to ensure data security. Base encoding is one of the commonly used encryption methods. This article will introduce some common operations on base encoding in PHP8, as well as specific code examples. 1. What is hexadecimal encoding? Base is a mathematical counting system that
