L
L
LiptonOlolo2016-06-29 08:16:37
Java
LiptonOlolo, 2016-06-29 08:16:37

Negative Byte?

Good morning!
There is a Java code like this

public static boolean GMSetGameAttriByte(byte type, byte value) throws Exception {
        OctetsStream os = new OctetsStream();
        os.marshal(value);
        return DeliveryDB.GMSetGameAttri(-1, type, (Octets)os);
    }

    public static byte GMGetDoubleExp() throws Exception {
        return DeliveryDB.GMGetGameAttriByte(-52);
    }

But I can’t understand how to make a negative byte, can someone tell me?
For those in the tank: need to figure out how to send a negative byte in C#.
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rou1997, 2016-06-29
@Rou1997

Firstly, you need a different GMGetGameAttriByte function, with 1 argument, and you have 2, and secondly, what kind of code is this in general?

A
aol-nnov, 2016-06-29
@aol-nnov

what's the mess in your head?
a byte is 8 bits. it is neither negative nor positive. these are eight bits, each of which can be either set or reset.
next level.
number encoding. integer (signed/unsigned), fixed point, floating point. you google it yourself.
here's a starter for you: signed integers - the most significant bit is reserved for the sign, from which the number of bits encoding the number decreases, (in the same bytes, unsigned 0-256, signed -127 +128 but a sign appears)
10000001 = this is 129 or minus one.

W
WarFollowsMe, 2016-06-29
@WarFollowsMe

If you have a server written in one language (Java), and a client in another (C#), byte types do not run between them, they send data to each other. Types are just descriptive structures of a programming language and have nothing to do with data. It's just easier for a programmer to get the value of byte myVar = 129 instead of 10000001.
byte in Java min value = -128, max value = 127.
byte in C# min value = 0, max value = 255
sbyte in C# min value = -128, max value = 127
My opinion is that you are simply entangled in three pines.
Another very important difference between Java and .Net is in byte order . .Net defaults to Little Endian, Java defaults to Big Endian. This information is not specific to your question, but it may be useful in the future.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question