|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
помогите перевести код с С на Delphi
вот исходный код на С. Помогите сделать из него ф-ю Delphi со string на входе
Код:
uint16_t WordCrc16 (uint8_t *Data, uint16_t size) { uint16_t w; uint8_t shift_cnt,f; uint8_t *ptrByte; uint16_t byte_cnt = size; ptrByte = Data; w = (uint16_t)0xffff; for (;byte_cnt>0;byte_cnt--) { w = (uint16_t)(w^(uint16_t)(*ptrByte++)); for (shift_cnt = 0; shift_cnt<8; shift_cnt++) { f=(uint8_t)((w)&(0x1)); w>>=1; if ((f) ==1) w = (uint16_t)((w)^0xa001); } } return w; } |
#2
|
||||
|
||||
Цитата:
Код:
function WordCrc16(const Data: AnsiString): Word; var w: Word absolute Result; shift_cnt, f: Byte; ptrByte: PByte; byte_cnt: Integer; begin byte_cnt := Length(Data); ptrByte := Pointer(Data); w := $FFFF; while byte_cnt > 0 do begin w := w xor ptrByte^; Inc(ptrByte); for shift_cnt := 1 to 8 do begin f := w and $1; w := w shr 1; if f = 1 then w := w xor $A001; end; Dec(byte_cnt); end; end; |