I am converting code that works in Java but not in C#
byte[] buffer = new byte[64];
this.buffer[((int)this.count & 0x3F)] = -128;
This generates a compile time error “Constant value ‘-128’ cannot be converted to a ‘byte’.” How can I store a negative number for a byte?
The
bytedata type in Java is signed (-128–127). The equivalent data type in C# issbyte.So the equivalent C# code is as follows:
If you want an array of unsigned bytes (0–255), the
bytewith the same bit pattern as thesbyte-128 is 128 (0x80).See also: Integral Types Table (C# Reference)