Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Fixed Point Numbers - Mathematics

1. ## Fixed Point Numbers - Mathematics

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);
}
}```

2. ## Re: Fixed Point Numbers - Mathematics

Cross-posted at stackoverflow: fixed-point-numbers. Please be sure to show links to all cross-posts to prevent folks from giving answers that have already been given. Your cooperation in this is greatly appreciated.

3. ## Re: Fixed Point Numbers - Mathematics

Oh okay, thanks. I didn't know there was such a rule. I wasn't trying to do anything sneaky. I just am looking to find all the help I can. I'll make sure to follow that rule in the future.

4. ## The Following User Says Thank You to BobDole6395 For This Useful Post:

Fubarable (July 11th, 2012)