UShort.java 885 B

12345678910111213141516171819202122232425262728293031
  1. package gnu.math;
  2. public class UShort extends UnsignedPrim implements Comparable<UShort> {
  3. short ival;
  4. public int numBits() { return 16; }
  5. public UShort(short ival) { this.ival = ival; }
  6. public static UShort valueOf(short ival) { return new UShort(ival); }
  7. public short shortValue() { return ival; }
  8. public int intValue() { return ival & 0xFFFF; }
  9. public long longValue() { return ival & 0xFFFF; }
  10. public IntNum toIntNum() { return IntNum.valueOf(ival & 0xFFFF); }
  11. public boolean equals(Object obj) {
  12. return obj instanceof UShort
  13. && ival == ((UShort) obj).ival;
  14. }
  15. public int compareTo(UShort other) {
  16. return intValue() - other.intValue();
  17. }
  18. public static String toString(short ival) {
  19. return Integer.toString(ival & 0xFFFF);
  20. }
  21. public String toString() { return toString(ival); }
  22. }