CRC16 in Java

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;
pipinana02Asked:
Who is Participating?
 
pipinana02Author Commented:
Hi girionis.. thanks a lot! The first link u provide me can works fine..

Thanks again!! :D
0
 
girionisCommented:
Thank you for accepting, glad I was of help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.