嗨,我只是有一个关于隐式转换的数据类型简短的问题。
这里说short n = 99999;
等于-31073的值。为什么等于那个数字?短路的最小数目为-32,768,最大为32,767(含)。另外,我不明白为什么这是负面的?
答案 0 :(得分:4)
答案 1 :(得分:3)
ZipArchive::setExternalAttributesName()
,////// Make Template archive object
$templateArchive = new ZipArchive();
$templateArchive->open(PATH_TO_TEMPLATES.'_files/'.$templateName.'/_pack/'.$templateName.'.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($templateDir."/templates/".$template_archive_name),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
// relative path is full path, reduced with length of templateDir string and 11 more chars for /templates/
$relativePath = substr($filePath, strlen($templateDir) + 11);
// Add regular files
if (!$file->isDir())
{
// Add current file to archive
$templateArchive->addFile($filePath, $relativePath);
}
elseif (substr($relativePath, -2) === "/.")
{
// Remove the dot representing the current directory
$relativePath = substr($relativePath, 0, -1);
// Add current directory to archive
$templateArchive->addEmptyDir($relativePath);
}
else
{
continue;
}
$templateArchive->setExternalAttributesName($relativePath,
ZipArchive::OPSYS_UNIX,
fileperms($filePath) << 16);
}
// Template Zip archive will be created only after closing object
$templateArchive->close();
等原始类型已签名,但int
除外。short
是16位带符号整数。 然后,对于char
整数short
,内部二进制文件类似于:
short
当我们在此数字上加1时,我们得到以下二进制:
32767
如果我们将其读为短符号,则为01111111 11111111
。
然后我们可以获取此映射:
10000000 00000000
对于“短” 99999,可以先将其减少为34463(= 99999%65536),然后由于此映射,应该从65536中减去32768和65535之间的任何数字,然后将34463映射到最终结果中-32768
。