diff --git a/src/ifcparse/IfcWrite.cpp b/src/ifcparse/IfcWrite.cpp index 78124c5d20..934651d3e6 100644 --- a/src/ifcparse/IfcWrite.cpp +++ b/src/ifcparse/IfcWrite.cpp @@ -350,7 +350,7 @@ private: oss.put('"'); oss << std::hex << std::setw(1); unsigned c = b.size(); - unsigned n = c % 4; + unsigned n = (4 - (c % 4)) & 3; oss << n; for (unsigned i = 0; i < c + n;) { unsigned accum = 0;