Ver Mensaje Individual
  #11  
Antiguo 18-02-2020
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola David.

Aunque tarde, por que ya el trabajo está hecho, te pongo los códigos que usé para mis pruebas.

C++
Código PHP:
...
#define USHORT unsigned short
...

int crc16(const string &dataUSHORT crc)
{
  
USHORT x(0);
  
int count data.length();

  while (--
count >= 0)
  {
    
USHORT z = (USHORT)(data[x++] << 8);
    
crc = (USHORT)(crc z);
    for(
int i 80; --i)
      
crc = (crc 0x8000) ? (USHORT)(crc << 0x1021) : (USHORT)(crc << 1);
  }
    return 
crc;
}

void main()
{
  
string data "13|0000123|1|Maximilian|Mustermann|05051999|21092019";

  
cout <<  crc16(data3077) << endl
Delphi:
Código Delphi [-]

function Crc16(const data: string; crc: Word): Word;
var
  x, z: Word;
  count, i: Integer;
begin
  count := Pred(data.Length);
  x     := 0;
  while (count >= 0) do
  begin
    Dec(count);
    Inc(x);
    z   := Word(data[x]) shl 8;
    crc := crc xor z;
    for i := 7 downto 0 do
      if crc and $8000 <> 0 then
        crc := (crc shl 1 xor $1021)
      else
        crc := (crc shl 1);
  end;
  Result := crc;
end;

...
var
  data : string;
begin
  data :=  '13|0000123|1|Maximilian|Mustermann|05051999|21092019';
  ShowMessage(Crc16(data,3077).ToString);
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 18-02-2020 a las 20:57:02.
Responder Con Cita