aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/function/UnsignedInteger.java
blob: 7feb33fb628a66b530e07ac8b8382d4e56e5e82e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
	}
}