I am stuck on a project in my intro to Java class.
We have to create a code that will convert a number to a Fixed Point Number. I've got that part okay, but where I am stuck is in the mathematics portion of our assignment. We have to add, subtract, multiple w/ (scalar (float) method, and divide with scalar (float) method.
Here is the code I have so far. If anyone could help point me in the right direction to getting a second number output and having the two numbers add, I would appreciate it.
public class FixedNumber { public static final int lastSix = Integer.parseInt("111111", 2); int value; int value2; public FixedNumber(int value) { this.value = value << 6; } public FixedNumber(int integral, float decimal) { this.value = (integral << 6) + (int)(decimal % 1 * 50); } public FixedNumber(float value) { this.value = ((int)value << 6) + (int)(value % 1 * 50); } public String toString() { return (value >> 6) + "." + ((value & lastSix) * 2); //return "" + ((value << 26) >>> 26); } public static void main(String[] args) { FixedNumber number = new FixedNumber(12786783, 0.87654f); //integral, decimal FixedNumber number2 = new FixedNumber(3.876545f); //value System.out.println(number); System.out.println(number2); } }