Solved

Java long division in finite field 2

Posted on 2011-09-14
8
358 Views
Last Modified: 2012-05-12
How do I do a long division in galois field 2 in java?
0
Comment
Question by:humansg
  • 4
  • 2
8 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
humansg, before we get started, is this for a homework assignment? If so, do you know how to work out the long division manually as I can help you translate that to Java, thus helping you "learn" versus just spitting out an answer...
0
 

Author Comment

by:humansg
Comment Utility
yes, it is part of an assignment which I need to call for part of euclid algorithm..
yes i know how to do the long division manually.
0
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
Okay. Great. Please post what you have for the calculation as you understand it in your attempt in Java. If you are getting any compilation or run-time errors, then you should post details on those. For run-time errors, posting the full stack trace in a code snippet is very useful. If the issue is logical, i.e., everything compiles and runs but you are not getting the expected results, then ensure to post what you expect alongside what you are getting currently.

From there, we can guide you through correcting the code.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
humansg earned 0 total points
Comment Utility
public static int gf2LongDivideQ(int dividend, int divisor) {

        int dividendLength = getLengthOf(dividend);
        int divisorLength = getLengthOf(divisor);

        if (divisorLength > dividendLength) {
            return -1;
        }

        int tempDividend = 0;

        int quotient = 0;

        for (int i = 1; i <= dividendLength; i++) {
            int bitAtPositionI = getBit(dividend, i);

            tempDividend = (tempDividend << 1) + bitAtPositionI;

            if (getLengthOf(tempDividend) < divisorLength) { // cannot divide
                // append '0' to end of quotient
                quotient = (quotient << 1);
            } else {
                // perform xor operation
                tempDividend = tempDividend ^ divisor;

                // append '1' to end of quotient
                quotient = (quotient << 1) + 1;
            }
        }

        return quotient;
    }

    public static int getLengthOf(int input) {
        int length = 0;
        while (input != 0) {
            input = input >> 1;
            length++;
        }
        return length;
    }

    public static int getBit(int input, int index) {
        input = input >> (getLengthOf(input) - index); // shift out bits to the right by (length - index)
        input = input & 0x1; // get right most bit
        return input;
    }

Open in new window

0
 

Author Closing Comment

by:humansg
Comment Utility
Coded out myself. Should be able to work..
0
 

Author Comment

by:humansg
Comment Utility
accepting own solution..
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 36
java set up 1 44
wordappend challenge 8 82
PDFBox - convert image to PDF, PDF resolution 3 59
Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now