[英]Casting hex number to signed integer
I have been trying to cast a hex number to signed integer.我一直在尝试将十六进制数转换为有符号整数。 But its not recognizing negative number.
但它不承认负数。
Here is an example.这是一个例子。 Do I need to sign extend separately instead of casting?
我是否需要单独签署扩展而不是强制转换?
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World";
int64_t input = static_cast<int64_t>(0xf8546);
cout << "Input: " << input << endl;
return 0;
}
There are no such things as negative literals in C++. C++ 中没有否定字面量之类的东西。
0xf8546
is positive. 0xf8546
为正。 Its type depends on your platform.它的类型取决于您的平台。
If you want a negative hexadecimal number then write如果你想要一个负的十六进制数,那么写
-0xf8546
This consists of the unary negation operator applied to the literal 0xf8546
, in the same way that -1
is the unary negation of the literal 1
.这包括应用于文字
0xf8546
的一元否定运算符,就像-1
是文字1
的一元否定一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.