我在 C# 中有这段代码
byte[] t = {6, 250, 215}
。
但是在Java中是
byte[] t = {6, -6, -41}
。
如何解决这个问题?
最佳答案
How to solve this problem
第一个是关于how java represents data types的阅读..:
byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.
作为@bradimus语句,java的byte是一个8位2补码signed int 但在 C# 中,您永远不会看到负字节值
提示:
如果您考虑进行转换...
-6 in java can be 256+(-6) = 250 in C#
如果需要从 C# 转换为 java,请仔细考虑 java 字节中的最大值和最小值....
关于java - 如何将 byte[] c# 转换为 java byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38511711/