Converting unsigned to java signed byte value

Hey ,

i need to use a raw address in a client i am writing but, of course, the address contains a byte outside of the java signed byte range. if any one could tell me what an unsigned byte of 224 in signed java is i would be very grateful, if you could also show how you did this it would be appreciated. thank you =)

[330 byte] By [Adamski84a] at [2007-11-27 10:56:26]
# 1

> Re: Converting unsigned to java signed byte value

>

> i need to use a raw address in a client i am writing

> but, of course, the address contains a byte outside

> of the java signed byte range.

> if any one could tell

> me what an unsigned byte of 224 is in signed java

> I would be very grateful, if you could also show how

> you did this it would be appreciated. thank you =)

You misunderstand signed/unsigned.

A byte has 8 bits. It can represent 256 different values.

Viewed as an unsigned scalar the range is [0;255].

Viewed as a signed two's-complement scalar the range is [-128;127].

Values [0;127] are obviously the same byte values in the two views.

What the other half of the possible byte values represent depends on what view you adopt.

You don't need to convert anything.

public final class Byte224 {

static byte[] byteArray = {

(byte)224, (byte)'\n'

};

public static final void main(final String[] arg) {

System.out.println("0x"+Integer.toHexString(byteArray[0]&0xff));

System.out.println(Integer.toString(byteArray[0]&0xff));

}

}

tschodta at 2007-7-29 12:02:56 > top of Java-index,Java Essentials,New To Java...