Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. compare Qt's CRC and boost's crc algorithms
Forum Updated to NodeBB v4.3 + New Features

compare Qt's CRC and boost's crc algorithms

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 192 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DungeonLords
    wrote on last edited by DungeonLords
    #1

    I want to calc CRC using not Qt's qChecksum but using boost library. CRC algo should be the same. How calc?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DungeonLords
      wrote on last edited by DungeonLords
      #2

      Qt use CRC algo "ISO/IEC 3309" with well-known alias "CRC-16/ISO-HDLC, CRC-16/ISO-IEC-14443-3-B, CRC-16/X-25, CRC-B, X-25", see details. This code to compare Qt's CRC and boost's crc algorithms

      #include <QCoreApplication>
      #include <boost/crc.hpp>
      using namespace boost;
      typedef crc_optimal<16, 0x1021, 0xffff, 0xffff, true, true> crc_16_X25;
      
      QString u16Hex(const quint16 value){
          return QString("0x"+QString("%1").arg(value, 4, 16, QChar('0')).toUpper());
      }
      
      void calc(){
          std::array<quint16, 3> arr= {0x0000, 0x0000}; //there is two data elements and third element to keep crc itself
          crc_16_X25 crc_boost{};
          //crc.reset(); //no need because we calc crc first time; use in case of reuse
          crc_boost.process_block(arr.cbegin(), &arr.at(1)); //calc crc of two elements
          arr[2]= crc_boost.checksum();
          QByteArray b= QByteArray::fromHex("0000");
          const quint16 crc_Qt= qChecksum(b);
          qDebug() << "Qt" << u16Hex(crc_Qt) << "boost" << u16Hex(arr[2]) ;
      }
      
      int main(int argc, char *argv[]){
          QCoreApplication a(argc, argv);
          calc();
      
          QMetaObject::invokeMethod(&a, "quit", Qt::QueuedConnection);
          return a.exec();
      }
      
      

      Output:

      Qt "0x0F47" boost "0x0F47"
      

      See how to build boost library for CRC part here

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved