|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |
java.lang.Object java.lang.Enum<Word> com.faunos.util.io.Word
public enum Word
An enumeration of the data widths. As of this writing, the data widths correspond to that
of the primitives: byte
, short
, int
, and long
.
Enum Constant Summary | |
---|---|
BYTE
|
|
INT
|
|
LONG
|
|
SHORT
|
Method Summary | |
---|---|
static Word |
forWidth(int width)
|
long |
fromNativeBits(long bits)
Returns value of the given bit field interpreted in this word format. |
long |
getHiBit()
Returns the high bit of this Word as a bit mask, with the
high bit on (1) and the rest of the bits zero.. |
long |
getHiBitComplement()
Returns the complement of the high bit for this Word . |
long |
getMaxValue()
Returns the maximum signed value the Word can represent. |
long |
getMinValue()
Returns the maximum signed value the Word can represent. |
byte |
getWidth()
Returns the width of this word in bytes. |
boolean |
inRange(long value)
Determines whether the given value can be represented
using an integral value of this word width. |
long |
read(ByteBuffer in)
Reads width amount of bytes from the given
buffer and interprets it as a signed value (big endian two's complement)
and returns the result |
long |
toNativeBits(long value)
Returns this enum instance's native, 2's complement representation of the specified signed value . |
static Word |
valueOf(String name)
Returns the enum constant of this type with the specified name. |
static Word[] |
values()
Returns an array containing the constants of this enum type, in the order they're declared. |
void |
write(ByteBuffer out,
byte value)
Writes the given value to the given out buffer. |
void |
write(ByteBuffer out,
int value)
Writes the given value to the given out buffer. |
void |
write(ByteBuffer out,
long value)
Writes the given value to the given out buffer. |
void |
write(ByteBuffer out,
short value)
Writes the given value to the given out buffer. |
Methods inherited from class java.lang.Enum |
---|
clone, compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Enum Constant Detail |
---|
public static final Word BYTE
public static final Word SHORT
public static final Word INT
public static final Word LONG
Method Detail |
---|
public static final Word[] values()
for(Word c : Word.values()) System.out.println(c);
public static Word valueOf(String name)
name
- the name of the enum constant to be returned.
IllegalArgumentException
- if this enum type has no constant
with the specified namepublic byte getWidth()
public long getMaxValue()
Word
can represent.
public long getMinValue()
Word
can represent.
public long getHiBit()
Word
as a bit mask, with the
high bit on (1) and the rest of the bits zero.. For example,
the BYTE
enum instance returns 0x80L
.
1L << (8 * getWidth() - 1)
public long toNativeBits(long value)
value
. (For nonnegative values that are
in range, this method just returns the
same value
.) The returned value is bit-wise equivalent
to the value's representation in this word format.
Note that if the given value
is not in range, then the value's high bytes will be truncated and ignored.
fromNativeBits(long)
,
getHiBit()
public long fromNativeBits(long bits)
bits
to this word width.
toNativeBits(long)
,
getHiBit()
public long getHiBitComplement()
Word
.
~(1L << (8 * getWidth() - 1))
public long read(ByteBuffer in)
width
amount of bytes from the given
buffer and interprets it as a signed value (big endian two's complement)
and returns the result
in
- the buffer read from. The position is advanced by the width
of this Word
public void write(ByteBuffer out, byte value)
value
to the given out
buffer.
The position of the buffer is advanced by width
amount.
public void write(ByteBuffer out, short value)
value
to the given out
buffer.
The position of the buffer is advanced by width
amount.
public void write(ByteBuffer out, int value)
value
to the given out
buffer.
The position of the buffer is advanced by width
amount.
public void write(ByteBuffer out, long value)
value
to the given out
buffer.
The position of the buffer is advanced by width
amount.
public boolean inRange(long value)
value
can be represented
using an integral value of this word width.
value >= minValue && value <= maxValue
public static Word forWidth(int width)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |