gpt4 book ai didi

c++ - 减去无符号并得到有符号

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:29:05 25 4
gpt4 key购买 nike

我可以这样转换吗?

int clockOffset;

clockOffset=((int64_t)Time_1_delayed-Time_1-Time_2_delayed+Time_2)/2;

其中所有时间变量都是 uint

我想在 clockOffset 中得到签名结果。

最佳答案

这是您可以在 C 中执行的操作(假设 int 和 unsigned int 比 long long 短):

#include <limits.h>

...
unsigned int Time_1_delayed, Time_1, Time_2_delayed, Time_2;
...
long long diff = ((long long)Time_1_delayed - Time_1 - Time_2_delayed + Time_2) / 2;
int clockOffset;

if (diff < INT_MIN || diff > INT_MAX)
HandleTheError();

clockOffset = diff;
...

关于c++ - 减去无符号并得到有符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14754634/

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