如果在您的情况下不起作用,那么其他事情就会出错。 (这是其他评论家已经告诉你的。)
我怎么能说服你呢?
我最后的(绝望)尝试:一个(不那么)MCVE:
#include
#include
int main()
{
QString samples[] = {
"0x0", "0x1", "0x1e", "0x11", "0x1111", "0x111e", "0x111f"
};
enum { n = sizeof samples/sizeof *samples };
for (int i = 0; i < n; ++i) {
const QString &hexString = samples[i];
qDebug() << "Formatted binary output of " << hexString;
for (int j = 1; j < 40; j += 8) {
bool ok;
qDebug()
<< QString("%1: %2")
.arg(j, 2)
.arg(hexString.toULongLong(&ok, 16), j, 2, QChar('0'));
}
}
// done
return 0;
}
编译和测试:
Formatted binary output of "0x0"
" 1: 0"
" 9: 000000000"
"17: 00000000000000000"
"25: 0000000000000000000000000"
"33: 000000000000000000000000000000000"
Formatted binary output of "0x1"
" 1: 1"
" 9: 000000001"
"17: 00000000000000001"
"25: 0000000000000000000000001"
"33: 000000000000000000000000000000001"
Formatted binary output of "0x1e"
" 1: 11110"
" 9: 000011110"
"17: 00000000000011110"
"25: 0000000000000000000011110"
"33: 000000000000000000000000000011110"
Formatted binary output of "0x11"
" 1: 10001"
" 9: 000010001"
"17: 00000000000010001"
"25: 0000000000000000000010001"
"33: 000000000000000000000000000010001"
Formatted binary output of "0x1111"
" 1: 1000100010001"
" 9: 1000100010001"
"17: 00001000100010001"
"25: 0000000000001000100010001"
"33: 000000000000000000001000100010001"
Formatted binary output of "0x111e"
" 1: 1000100011110"
" 9: 1000100011110"
"17: 00001000100011110"
"25: 0000000000001000100011110"
"33: 000000000000000000001000100011110"
Formatted binary output of "0x111f"
" 1: 1000100011111"
" 9: 1000100011111"
"17: 00001000100011111"
"25: 0000000000001000100011111"
"33: 000000000000000000001000100011111"
注:
冒号前(:)数量提供使用的字段宽度。
示例输出显示如果使用字段宽度提供的数字量不能正确显示结果数字,则输出可能会变长。
这与文档中描述的完全相同。 (由我强调):
fieldWidth指定一个被填充到