gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:40 25 4
gpt4 key购买 nike

我在 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 inplace of int where their limits help to clarify your code; the factthat a variable's range is limited can serve as a form ofdocumentation.

作为@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/

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