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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Fixed Point Numbers - Mathematics

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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. #2
    Member
    Join Date
    Jul 2012
    Posts
    83
    My Mood
    Cynical
    Thanks
    3
    Thanked 9 Times in 9 Posts

    Default 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. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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)

Similar Threads

  1. Trouble adding exceptions to fixed queue class
    By Farmer in forum Exceptions
    Replies: 5
    Last Post: December 19th, 2011, 07:23 AM
  2. [METHOD] How: Count how many prime numbers there is between two numbers!
    By Secret20 in forum Object Oriented Programming
    Replies: 4
    Last Post: October 18th, 2011, 02:30 PM
  3. [SOLVED] Fixed Null Pointer Exception but still have another problem
    By javapenguin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 29th, 2010, 10:16 PM
  4. Adding fixed size picture and button to panel
    By Javabeginner in forum AWT / Java Swing
    Replies: 10
    Last Post: August 23rd, 2010, 06:07 PM
  5. [SOLVED] Problem with nth square root of any number
    By Freaky Chris in forum Java Theory & Questions
    Replies: 7
    Last Post: May 14th, 2009, 04:46 PM