Solved

Java long division in finite field 2

Posted on 2011-09-14
8
360 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
ID: 36539976
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
ID: 36543181
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
ID: 36543269
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Accepted Solution

by:
humansg earned 0 total points
ID: 36556907
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
ID: 36585517
Coded out myself. Should be able to work..
0
 

Author Comment

by:humansg
ID: 36556915
accepting own solution..
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 97
simple java question 3 55
xampp tool 12 49
Lock or digital lock that are lockable from both inside plus outside 12 55
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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