diff options
Diffstat (limited to 'src/jcgp/backend/function/UnsignedInteger.java')
-rw-r--r-- | src/jcgp/backend/function/UnsignedInteger.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/jcgp/backend/function/UnsignedInteger.java b/src/jcgp/backend/function/UnsignedInteger.java new file mode 100644 index 0000000..7feb33f --- /dev/null +++ b/src/jcgp/backend/function/UnsignedInteger.java @@ -0,0 +1,66 @@ +package jcgp.backend.function; + +/** + * Integer wrapper type for unsigned integer values. + * <br><br> + * 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. + * <br><br> + * 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); + } +} |