Java bytes -128...+127 vs. normal byte range issue

Hi All

Ok, say for example we use a tile map editor such as mappy (www.tilemap.co.uk) to create a map file for a game. The range of tiles we have can be anything from 0…255, i.e. a standard byte.

The standard byte in java has a range from -128…127. Can this cause any issues and is there anyway to deal with this?

Also I would like to know how an Image deals with RGB values for every pixel. maybe they are short or int values but that takes up too much space, (of course we can always use colour pallettes) so if we want to use a byte for each value and the max range is only 128 we will have some problems… what is the actual implementation?

unless of course we convert the negative numbers to their positive counterparts using some bit operations…

any thoughts / suggestions / solutions are most welcome. Also is this actually a problem you may have come accross in developing your games or is it really not a cause for concern?

Thanks

In memory 255 looks the same as -1, and 128 looks like -128. It all depends on how the value is interpreted. As long as you are aware of this you can deal with any issues that might arise.

This is device specific. It depends on the actual hardware and the decisions the implementors of the KVM took. The most common approach is having RGB values stored in the smallest amount of memory that can handle all the available colors. The maximum value of 128 is a non-issue since this stuff is implemented natively and not in Java.


byte b = (byte)255;
System.out.println("b=" + b);
int i = (int)b & 0xff;
System.out.println("i=" + i);

If you understand what’s going on behind the scenes (ie, in the memory), then no issue that this arises will become a showstopper. I hope this response helps you achieve that understanding.

shmoove