gpt4 book ai didi

c++ - 值中的串联位

转载 作者:搜寻专家 更新时间:2023-10-31 01:09:14 25 4
gpt4 key购买 nike

我需要连接位,例如:

0x10 plus 0x12 = 0x1012
or
0x123 plus 0x4 = 0x1234

如果没有字符串类,我该怎么做?

最佳答案

您必须评估最右边值的排名。

我相信,这样的事情应该可行:

// Returns rank of the value increased by one (except, when value == 0)
int rank(int value)
{
int result = 0;
while (value > 0)
{
value /= 16;
result++;
}

return result;
}

int main(int argc, char * argv[])
{
int left = 0x12;
int right = 0x34;

int sum = (left << (4 * rank(right))) + right;

printf("%x\n", sum);
}

关于c++ - 值中的串联位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17206878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com