package jcgp.backend.function; /** * Integer wrapper type for unsigned integer values. *

* Java offers no support for unsigned types save from * unsigned conversion methods. This class uses those methods * to simulate the unsigned int data type, useful for circuit * truth table encodings. *

* When a string representation of an unsigned integer is parsed * using Integer.parseUnsignedInt(), an Integer is created using * all 32 bits for unsigned magnitude. The integer however is still * signed and will behave as such for all arithmetic operations. * Bitwise operations can still be performed as they work at the bit * level, making this data type particularly suitable for circuit design. * * * @author Eduardo Pedroni * @see Integer * */ public class UnsignedInteger { private Integer value; /** * Makes a new instance of UnsignedInteger with a specified value. * * @param i the value with which to initialise */ public UnsignedInteger(int i) { value = new Integer(i); } /** * Makes a new instance of UnsignedInteger with a specified value. * * @param i the value with which to initialise */ public UnsignedInteger(Integer i) { value = i; } /** * Makes a new instance of UnsignedInteger from the string representation * of an unsigned integer. * * @param i the string with which to initialise */ public UnsignedInteger(String i) { value = Integer.parseUnsignedInt(i); } /** * @return the wrapped Integer object */ public Integer get() { return value; } @Override public String toString() { return Integer.toUnsignedString(value); } }