// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
bool Crc8::Generate(constunsignedchar *data, int length, unsignedchar* check_sum) { if (!check_sum) returnfalse;
*check_sum = 0; if (!data) returnfalse;
// The inital and final constants are as used in the ATM HEC. staticconstunsignedchar kInitial = 0x00; staticconstunsignedchar kFinal = 0x55; unsignedchar crc = kInitial; for (int i = 0; i < length; ++i) {
crc = kCrcTable[(data[i] ^ crc) & 0xFFU];
}
*check_sum = crc ^ kFinal; returntrue;
}
bool Crc8::Verify(constunsignedchar* data, int length, unsignedchar check_sum, bool* matches) { if (!matches) returnfalse;
*matches = false; if (!data) returnfalse;
unsignedchar calculated_crc; if (!Generate(data, length, &calculated_crc)) returnfalse;
*matches = check_sum == calculated_crc;
returntrue;
}
} // namespace rlz_lib
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.