java - 如何将 byte[] c# 转换为 java byte[]

标签 java c# arrays range byte

我在 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/

相关文章:

java - Spring REST 存储库继承空值

java - 自组织搜索程序

c# - 保存 PictureBox 图像时为 "A generic error occurred in GDI+"

Javascript 重写之前的值?

java - 使用 getBinaryStream 读取单元格

java - 为什么转换方向在原始类型中从大到小,在对象中从小到大?

c# - 非嵌入资源js文件可以访问资源文件(.resx)吗?

c# - 返回到代码块的开头?

java - 读取txt文件并将每一列添加到java中的不同数组

c# - 计算数组中元素的数量