Java代码 - 在字节数组C#负的字节 [英] Java code - negative byte in byte array to C#

查看:147
本文介绍了Java代码 - 在字节数组C#负的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中我有以下行:

In Java I have the following line:

new byte[]{59, 55, 79, 1, 0, 64, -32, -3};



不过,在C#中,我不能在一个字节数组使用负的字节。我试着浇铸成字节,它失败了。我能做什么?谢谢!

However, in C# I can't use negative bytes in a byte array. I tried casting it to byte and it failed. What can I do? thanks!

推荐答案

由于是的符号的。在Java中,字节的签署

Because in C# bytes are unsigned. In Java, bytes are signed.

从的 字节结构

字节是表示与范围从0(这是由Byte.MinValue $ b $常数b表示)$ b $的b值255无符号整数(这是由Byte.MaxValue表示的不可变值型常数)

Byte is an immutable value type that represents unsigned integers with values that range from 0 (which is represented by the Byte.MinValue constant) to 255 (which is represented by the Byte.MaxValue constant)

从的 基本数据类型

字节的数据类型是一个8位有符号二进制补码整数。它具有-128
A最小值及127

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

我该怎么办?

您可以使用的 为sbyte 在C#中代表8位有符号整数。

You can use sbyte in C# which represents 8-bit signed integer.

该为SByte值类型表示其值范围从
负128至正127整数

The SByte value type represents integers with values ranging from negative 128 to positive 127.

等;

sbyte sb = new sbyte[] {59, 55, 79, 1, 0, 64, -32, -3};

这篇关于Java代码 - 在字节数组C#负的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆