-4
我有一个int(16比特)阵列:{10,-20,30,-40}我想:装配|转换32位负数到其未签署rerepresentation(也在32位)
- 到求和阵列,并显示该结果作为unsinged 32位数字
- 总结阵列,并显示该结果作为32位数字(签名)
这意味着:
32 bit un-signed : 131052
32 bit negative Number positive : -20
我有一个int(16比特)阵列:{10,-20,30,-40}我想:装配|转换32位负数到其未签署rerepresentation(也在32位)
这意味着:
32 bit un-signed : 131052
32 bit negative Number positive : -20
这不是一个都清楚你到底是什么。三个明显的可能性会看起来是这样的:
#include <iostream>
#include <numeric>
int main() {
short array[] = {10, -20, 30, -40};
std::cout << std::accumulate(array, array+4, (unsigned short)0) << "\n";
std::cout << std::accumulate(array, array+4, 0U) << "\n";
std::cout << std::accumulate(array, array+4, (short)0) << "\n";
return 0;
}
我不能肯定你是怎么想的,你可以得到131052如同一个结果 - 这不是你从任何一个16位或得到一个32位的和。