Java: confirm method Binary division and find remainder is correct?
Posted
by cadwag
on Stack Overflow
See other posts from Stack Overflow
or by cadwag
Published on 2009-12-09T08:02:04Z
Indexed on
2010/04/14
5:23 UTC
Read the original article
Hit count: 368
I am parsing binary files and have to implement a CRC algorithm to ensure the file is not corrupted. Problem is that I can't seem to get the binary math working when using larger numbers.
The example I'm trying to get working:
BigInteger G = new BigInteger("11001", 2);
BigInteger M = new BigInteger("1110010000", 2);
BigInteger R = M.remainder(G);
I am expecting:
R = "0101"
But I am getting:
R = "1100"
I am assuming the remainder of 0101 is correct since it is given to me in this book I am using as a reference for the CRC algorithm (it's not based in Java), but I can't seem to get it working. I can get small binary calculations to work that I have solved by hand, but not the larger ones. I'll admit that I haven't worked the larger ones by hand yet, that is my next step, but I wanted to see if someone could point out a glaring flaw I have in my code.
Can anyone confirm or deny that my methodology is correct?
Thanks
© Stack Overflow or respective owner