aspose file tools*
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
Author

Checksum

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
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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?


Steve
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Checksum