|
Simple Machine | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectutil.UnsignedByte
public class UnsignedByte
An UnsignedByte
is like a Byte
, but its values range from 0 to 255 instead of -128 to 127.
Most languages have a native unsigned-byte type (e.g., C, C++, C#), but Java doesn't.
When manipulating bytes as bit sequences, as we do in the CPU implementation, it is helpful to treat them as unsigned. The key difference between unsigned and signed in our context is what happens when you assign an (unsigned) byte to an integer. If a signed byte is assigned, then the resulting integer is sign extended (i.e., 0xff becomes 0xffffffff). If an unsigned byte is assigned, then the resulting integer is zero extended (i.e., 0xff becomes 0x000000ff). The former behaviour is what you want if the program thinks of the byte as a signed integer (i.e., -1 stays -1). The later is what you want if the program (in our case the CPU class) thinks of the byte as a sequence of bits.
Constructor Summary | |
---|---|
UnsignedByte(Byte aByte)
Create an unsigned byte from a byte. |
|
UnsignedByte(int anInt)
Create an unsigned byte from an integer. |
Method Summary | |
---|---|
boolean |
equals(Object o)
Like Java Numbers, two UnsignedByte's are equal if their values are equal. |
long |
value()
Get the value of the unsigned byte. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UnsignedByte(Byte aByte)
public UnsignedByte(int anInt)
Method Detail |
---|
public long value()
public boolean equals(Object o)
equals
in class Object
|
Simple Machine | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |