Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.lang.Number | +----mil.navy.nps.util.UnsignedByte
Note that you can't retrieve the value of this as a byte, simply because a negative value for an unsigned byte (as the signed value 242 would be) is invalid, and can't be represented. So we have to promote the bloody thing to an int.
Hmmmmm....should the internal representation be a short or a byte? I vote for byte, since it requires less storage in memory, and we might have a lot of these floating about. But we're constantly promoting it to an int or short anyway...
This implementation works by exploiting the characteristics of how numbers are stored internally. Just about all systems, except for a few obsolete machines, use "two's-complement" format for storing integer values. A signed byte will have this sequence as more and more bits are flipped on:
0,1,2,3....125,126,127,-128,-127,-127,...-1
The values roll over from (2^7)-1 to -(2^7) at the midpoint. Adding
one to 127 will result in -128, adding two results in -127, etc. We
can fake up unsigned bytes by exploiting this behavior. The maximum
an unsigned byte can represent is 255 (2^8 - 1) so we can translate
between a negative value and its unsigned positive representation with
this formula:
which means that -128 is mapped to 128, -126 to 129, and so on.
255 + _data + 1
This implements the Cloneable interface, which means that when we clone() something we can do a bitwise field copy (shallow copy). This needs to change if we ever have any actual objects contained in this class.
Field Summary | |
static short | MAX_UNSIGNED_BYTE_VALUE
|
Constructor Summary | |
UnsignedByte()
UnsignedByte object and intializes its value to 0.
|
|
UnsignedByte(byte pData)
UnsignedByte object from a signed byte,
throws an exception if the paraneter is out of range.
|
|
UnsignedByte(short pData)
UnsignedByte object from a short,
throws an exception if the parameter is out of range.
|
|
UnsignedByte(int pData)
UnsignedByte object from an int,
throws an exception if the parameter is out of range.
|
Method Summary | |
java.lang.Object | clone()
UnsignedByte object.
|
void | debugTest()
|
void | deSerialize(java.io.DataInputStream pInputStream)
|
double | doubleValue()
|
float | floatValue()
|
int | intValue()
|
long | longValue()
|
void | serialize(java.io.DataOutputStream pOutputStream)
|
java.lang.String | toString()
UnsignedByte value.
|
Methods inherited from class java.lang.Number |
byteValue, doubleValue, floatValue, intValue, longValue, shortValue |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
static final short MAX_UNSIGNED_BYTE_VALUE
Constructor Detail |
public UnsignedByte()
UnsignedByte
object and intializes its value to 0.public UnsignedByte(byte pData)
UnsignedByte
object from a signed byte,
throws an exception if the paraneter is out of range.
pData
- >=0
pData
is out of rangepublic UnsignedByte(short pData)
UnsignedByte
object from a short,
throws an exception if the parameter is out of range.
pData
- >=0, <=MAX_UNSIGNED_BYTE_VALUE
public UnsignedByte(int pData)
UnsignedByte
object from an int,
throws an exception if the parameter is out of range.
pData
- >=0, <=MAX_UNSIGNED_BYTE_VALUE
pData
is out of rangeMethod Detail |
public double doubleValue()
public float floatValue()
public int intValue()
public long longValue()
public void serialize(java.io.DataOutputStream pOutputStream)
outputstream
- the targetted output stream for this object
IOException
occurs.public void deSerialize(java.io.DataInputStream pInputStream)
inputstream
- the input stream that builds the object.
IOException
occurs.public java.lang.String toString()
UnsignedByte
value.public void debugTest()
public java.lang.Object clone()
UnsignedByte
object.Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |