Overview | Package | Class | Tree | Deprecated | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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()
Contructs a new UnsignedByte object and intializes its value to 0. |
|
UnsignedByte(byte pData)
Constructs an UnsignedByte object from a signed byte,
throws an exception if the paraneter is out of range. |
|
UnsignedByte(short pData)
Constructs an UnsignedByte object from a short,
throws an exception if the parameter is out of range. |
|
UnsignedByte(int pData)
Constructs an UnsignedByte object from an int,
throws an exception if the parameter is out of range. |
Method Summary | |
java.lang.Object | clone()
Makes a deep copy of the current UnsignedByte object. |
void | debugTest()
Of debugging interest only. |
void | deSerialize(java.io.DataInputStream pInputStream)
Reads an UnsignedByte in from DIS format. |
double | doubleValue()
Returns the current value of this object as a double float, after conversion. |
float | floatValue()
Returns a the current value of this object as a float, after conversion. |
int | intValue()
Returns the current value of this object as an int, after conversion. |
long | longValue()
Returns the current value of this object as a long, after conversion. |
void | serialize(java.io.DataOutputStream pOutputStream)
Writes out an UnsignedByte to an output stream. |
java.lang.String | toString()
Returns a String object representing this UnsignedByte value. |
Methods inherited from class java.lang.Number | |
byteValue, doubleValue, floatValue, intValue, longValue, shortValue |
Methods inherited from class java.lang.Object | |
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
- >=0pData
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_VALUEpublic UnsignedByte(int pData)
UnsignedByte
object from an int,
throws an exception if the parameter is out of range.
pData
- >=0, <=MAX_UNSIGNED_BYTE_VALUEpData
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 objectIOException
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.Overview | Package | Class | Tree | Deprecated | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |