Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

CRC16 in Java

Posted on 2006-05-29
4
Medium Priority
?
797 Views
Last Modified: 2008-01-09
Hi all,

Would like to ask the experts on how to do CRC16 calculation in Java? Currently I have the Delphi source code for the CRC16, but when I try to find for CRC16 java codes from the internet, all the codes I can find always return the wrong result :(

In the Delphi code, the CRC16 of "abcdefghi" (without the quotes) is 7729.

All source codes I can find from the internet always returned other values, and each codes returned different value from other code.. Is there many type of CRC16?

if it can help you, the following are the extract from the Delphi code:

-------------------------------------------

var
  Form1: TForm1;
  Crc16table : array[0..255] of word;
  value : word;

implementation

{$R *.dfm}


procedure TForm1.update(v : byte);
begin
  value := Crc16table[(value shr 8)and $FF] xor (value shl 8) xor (v and $FF);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j,k : integer;
  crc : word;
begin
  for i:= 0 to 255 do
  begin
    k := i shl 8;
    crc := 0;
    for j:= 0 to 7 do
    begin
      if (((crc xor k) and $8000) <> 0) then
        crc := (crc shl 1) xor $1021
      else
        crc := crc shl 1;
      k := k shl 1;
    end;
    Crc16table[i] := crc;
  end;
  for i:= 0 to 255 do
  begin
    memo1.Lines.Add(inttostr(Crc16table[i])+' ');
  end;
end;

function TForm1.getcrc(str:string):word;
var
 i : integer;
begin
  for i:=1 to (length(str)) do update(Ord(str[i]));
  result := value;
end;
0
Comment
Question by:pipinana02
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 600 total points
ID: 16783701
0
 

Author Comment

by:pipinana02
ID: 16787113
Hi girionis.. thanks a lot! The first link u provide me can works fine..

Thanks again!! :D
0
 
LVL 35

Expert Comment

by:girionis
ID: 16792710
Thank you for accepting, glad I was of help :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

569 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