如何使用php将十进制整数转换为字节?

如何使用php将十进制整数转换为字节?,php,math,int,decimal,byte,Php,Math,Int,Decimal,Byte,我需要得到多少字节是一个十进制整数与php。 例如,我如何知道使用php时256379是否为3字节? 我需要一个php函数将256379作为输入传递,并将3作为输出。如何获得它?表示一个数字所需的字节数可以这样计算: echo getNumBytes(256379); // Output: 3 echo getNumBytes(25637959676); // Output 5 function getNumBytes($num) { $i = 1; do {

我需要得到多少字节是一个十进制整数与php。 例如,我如何知道使用php时256379是否为3字节?
我需要一个php函数将256379作为输入传递,并将3作为输出。如何获得它?

表示一个数字所需的字节数可以这样计算:

echo getNumBytes(256379); // Output: 3
echo getNumBytes(25637959676); // Output 5

function getNumBytes($num) {
    $i = 1;
    do {
        $i++;
    } while(pow(256,$i) < $num);
    return $i;
}
echo ceil( log ($nmber, 256) );
echo getNumBytes(256379);//产出:3
echo getNumBytes(25637959676);//产出5
函数getNumBytes($num){
$i=1;
做{
$i++;
}而(pow(256,$i)<$num);
返回$i;
}

表示一个数字所需的字节数可以这样计算:

echo getNumBytes(256379); // Output: 3
echo getNumBytes(25637959676); // Output 5

function getNumBytes($num) {
    $i = 1;
    do {
        $i++;
    } while(pow(256,$i) < $num);
    return $i;
}
echo ceil( log ($nmber, 256) );
echo getNumBytes(256379);//产出:3
echo getNumBytes(25637959676);//产出5
函数getNumBytes($num){
$i=1;
做{
$i++;
}而(pow(256,$i)<$num);
返回$i;
}

您需要这样计算对数:

echo getNumBytes(256379); // Output: 3
echo getNumBytes(25637959676); // Output 5

function getNumBytes($num) {
    $i = 1;
    do {
        $i++;
    } while(pow(256,$i) < $num);
    return $i;
}
echo ceil( log ($nmber, 256) );

您需要这样计算对数:

echo getNumBytes(256379); // Output: 3
echo getNumBytes(25637959676); // Output 5

function getNumBytes($num) {
    $i = 1;
    do {
        $i++;
    } while(pow(256,$i) < $num);
    return $i;
}
echo ceil( log ($nmber, 256) );

PHP\u INT\u SIZE
常量告诉您整数值在PHP中有多大。。。。但我不明白从哪里可以得到3的可能值。。。。整数可以是4字节或8字节(32位或64位),并且对于您的PHP版本是一致的。。。。他们不会知道,在64位cpu上,当然是8,但是我怎么知道一个特定的十进制值是多少字节?例如,我如何知道25637959676是否为5字节?
PHP\u INT\u SIZE
常量告诉您整数值在PHP中的大小。。。。但我不明白从哪里可以得到3的可能值。。。。整数可以是4字节或8字节(32位或64位),并且对于您的PHP版本是一致的。。。。他们不会知道,在64位cpu上,当然是8,但是我怎么知道一个特定的十进制值是多少字节?例如,我如何知道25637959676是否为5字节?