File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Checksum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Checksum" Watch "Checksum" New topic


duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
hello all,
i am new in java and i have made a method for calculating the checksum.

i have a commad 01,0A,00,13,2,03,20,01,ff,25,02 for which the checksum i am calculating via xoring all bytes including the 1st byte, is E0. but i am getting wrong checksum, and i came to know that i have to skip the 1st byte. so kindly let me know where should i change my code in order to do the same and get the required result.

thanks in advance.
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

Where in your code do you do the XOR on each byte?

Under what condition does the first byte get processed?

How can you change that condition to skip the first byte?

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Your code is poorly formatted, making it hard to read. Proper indentation is a trivial thing to do right, and when you don't, it looks like you just don't care. When you post a question here, your job is to make it as EASY as possible for folks to help you.

My advice to you would be to start over. And by 'start over', I mean throw this code away. I have no idea if it's right or not, but it doesn't matter.

When you write code, you should start by thinking about the problem, and writing down the steps in English (or any natural language of your choice). Make sure you understand the entire problem. Literally, write down the steps involved in such detail that a 10 year old child could follow them.

Once once you have done all this should you write a line of code.

Even then, you should only write 2-3 lines at a time, re-compiling and testing as you go. Only write enough code to do the next step. Use lots of System.out.println() statements (that you later take out) to validate your code is doing what it needs to do.

If it were me, my first compile of my method would be doing nothing more than printing out "I'm in THIS method". I'd compile and test it. Then I'd pass in the String, and print out its value. Once I saw that work, I'd see about tokenizing it, and printing out the tokens.

It is a very iterative process, but it works.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Checksum
It's not a secret anymore!