做int top = uint8(data[2]);
给:TypeError: Type uint8 is not implicitly convertible to expected type int256.
。
和做int top = int(uint8(data[2]));
给予:TypeError: Explicit type conversion not allowed from "uint8" to "int256".
我使用的是语用^0.8
发布于 2021-10-10 19:35:12
这种转换是模棱两可的,取决于您如何进行转换,您可能会得到不同的结果。这就是为什么从0.8.0版本开始,编译器强迫您显式地告诉它您指的是哪个版本。
例如,如果data[2]
的值为255:
uint8
) -> -1 (int8
) -> -1 -> -1:255 (uint8
) -> 255 (uint
) -> 255 (int
)在上面,我假设data
是某种类型的uint8
数组--您没有指定它,如果不是,您可能需要额外的转换。根据您首先想要的转换,您需要其中之一:
int top = int(int8(data[2]));
int top = int(uint(data[2]));
https://stackoverflow.com/questions/69484658
复制相似问题